Found 33676 Articles for Programming

In C++ What are the differences between a pointer variable and a reference variable?

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

448 Views

ReferencesWhen a variable is declared as reference, it becomes an alternative name for an existing variable.SyntaxType &newname = existing name;InitializatioType &pointer; pointer = variable name;PointersPointers are used to store the address of variable.SyntaxType *pointer;InitializationType *pointer; pointer = variable name;The main differences between references and pointers are -References are used to refer an existing variable in another name whereas pointers are used to store address of variable.References cannot have a null value assigned but pointer can.A reference variable can be referenced by pass by value whereas a pointer can be referenced but pass by reference.A reference must be initialized on declaration ... Read More

Pointers vs References in C++

Revathi Satya Kondra
Updated on 21-Apr-2025 19:23:35

9K+ Views

In C++, both pointers and references are used to access and manipulate memory. But they behave differently. This guide explains each with simple words and examples. We understand the topic by learning how each is declared, used, and what differences exist between them. What are C++ Pointers? The pointers are used to store the address of a variable. We can change what they pointing to, and also can assign NULL to them. A pointer is similar to a signpost that contains the memory address of another variable, and you can directly access or change the variable by its address. Syntax ... Read More

How to delete a column from an existing table in a database using JDBC API?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

784 Views

You can delete a column in a table using the ALTER TABLE command.SyntaxALTER TABLE table_name DROP COLUMN column_name;Assume we have a table named Sales in the database with 7 columns namely id, CustomerName, DispatchDate, DeliveryTime, Price and, Location as shown below:+----+-------------+--------------+--------------+--------------+-------+----------------+ | id | productname | CustomerName | DispatchDate | DeliveryTime | Price | Location     | +----+-------------+--------------+--------------+--------------+-------+----------------+ | 1  | Key-Board   | Raja         | 2019-09-01   | 08:51:36     | 7000  | Hyderabad      | | 2  | Earphones   | Roja         | 2019-05-01   ... Read More

Passing by pointer Vs Passing by Reference in C++

Revathi Satya Kondra
Updated on 17-Apr-2025 18:40:27

3K+ Views

In C++, If we want to pass arguments to functions we can either pass the actual value, a pointer to the value, or a reference to the value. This concept becomes crucial when we want a function to modify the original variable. So, if we pass parameter to a function either by pass by pointer or pass by reference it will produce the same result. Only difference is that References are used to refer an existing variable in another name whereas pointers are used to store address of variable. It is safe to use reference because it cannot be NULL. ... Read More

How to change the datatype of a column in an existing table using JDBC API?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

882 Views

You can change the datatype of a column in a table using the ALTER TABLE command.SyntaxALTER TABLE Sales MODIFY COLUMN column_name column_new_datatuypeAssume we have a table named Sales in the database with 7 columns namely ProductName, CustomerName, DispatchDate, DeliveryTime, Price, Location and, ID with description as:+--------------+--------------+------+-----+---------+-------+ | Field        | Type         | Null | Key | Default | Extra | +--------------+--------------+------+-----+---------+-------+ | ProductName  | varchar(255) | YES  |     | NULL | | | CustomerName | varchar(255) | YES  |     | NULL ... Read More

References in C++

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

293 Views

A reference variable is an alias, that is, another name for an already existing variable. Once a reference is initialized with a variable, either the variable name or the reference name may be used to refer to the variable.References vs PointersReferences are often confused with pointers but three major differences between references and pointers are −You cannot have NULL references. You must always be able to assume that a reference is connected to a legitimate piece of storage.Once a reference is initialized to an object, it cannot be changed to refer to another object. Pointers can be pointed to another ... Read More

Execute both if and else statements in C/C++ simultaneously

Revathi Satya Kondra
Updated on 17-Apr-2025 18:39:52

430 Views

In this article, we will see how to execute the if and else section simultaneously in a C or C++, code. This solution is a little bit tricky. When the if and else are executed one after another then it is like executing statements where if-else are not present. But here we will see if they are present how to execute them one after another. Let's go through the different ways to simulate execution of both if and else blocks. This may include using functions, macros, or separating logic completely. Using Separate Functions ... Read More

Levels of Pointers in C/C++

Revathi Satya Kondra
Updated on 11-Apr-2025 22:04:00

328 Views

In C/C++, the pointers have multiple levels, which means a pointer can point to another pointer – so the chains of indirection can go on and on. For instance, a pointer to a variable's address is stored at "*ptr" (single-level pointer) while, at "**ptr", the address of another pointer is kept (a double-level pointer), so on. This is useful in allocating memory dynamically, working with multi-dimensional arrays, and handling complicated data structures.Following is the list of different levels of pointers. Let us understand these with the help of examples: Single Level Pointer ... Read More

How to add a new column to an existing table using JDBC API?

Nitya Raut
Updated on 30-Jul-2019 22:30:25

3K+ Views

You can add a new column to a table using the ALTER TABLE command.SyntaxALTER TABLE table_name ADD column_name datatype;Assume we have a table named Sales in the database with 5 columns namely ProductName, CustomerName, DispatchDate, DeliveryTime, Price and, Location as shown below:+-------------+--------------+--------------+--------------+-------+----------------+ | ProductName | CustomerName | DispatchDate | DeliveryTime | Price | Location       | +-------------+--------------+--------------+--------------+-------+----------------+ | Key-Board   | Raja         | 2019-09-01   | 08:51:36     | 7000  | Hyderabad      | | Earphones   | Roja         | 2019-05-01   | 05:54:28     | 2000 ... Read More

How does #include work in C++?

Revathi Satya Kondra
Updated on 17-Apr-2025 18:38:17

3K+ Views

In C++, the is a header file. This file includes all standard library. Sometimes in some coding contests, when we have to save time while solving, then using this header file is helpful. In software engineering approach we should reduce the minimize the include. Using this header file, it will include lots of files, sometimes that may not be required in the program. So it may increase the compile time and program size. The disadvantages of this header file is listed below. This is ... Read More

Advertisements