Skip to main content

How do you declare and initialize pointer variable ? Explain



Answer:

Pointer variables declaration: Pointer variables are used to store the address of the variable. And a pointer variable can store only the address of the variable which has the same data-type as the pointer variable.


General form:
            data-type  *pointer-variable name;
Example:
             int *ptr;
In the above example we have declare the pointer variable with the name of ‘ptr’ and its data-type in int, that means it can store the address of the variable which is of integer type.
 Initialization of pointer variables: The initialization of the pointer variable is simple like other variable but in the pointer variable we assign the address instead of value.
Example:
            int  *ptr,var1;
            ptr=&var1;
Here in the above example we have a pointer variable and another is a simple integer variable and we have assign the pointer variable with the address of the ‘var1’. That means the pointer variable ‘ptr’ is now has the address of the variable ‘var1’.
If we want to access the pointer variable then we have to understand the most important thing which is as follows:

If the ‘*’ asterisk sign is before the pointer variable this means the pointer variable is now pointing to the value at the location instead of the pointing to location.

Popular posts from this blog

Draw the basic organization of computer

Answer:                 The basic organization of computer__ Input Unit: ·          It accepts (or reads) instructions and data from outside. ·          It converts these instructions and data in computer acceptable form ·          It supplies the converted instructions and data to the computer system for further processing. Central Processing Unit (CPU): Control Unit: Control unit of a computer system manages and coordinates the operations of all other components of the computer system. Arithmetic Logic Unit(ALU): Arithmetic logic unit of a computer system is the place, where the actual executions of instruction, takes place during processing operation. Storage Unit: Primary Memory: It is volatile ( loses data on power ...

Describe the four basic data types. How could we extend the range of values they represent?

Answer: The basic four data types are: Data Type Integer Type Character Type Floating Point Type Void Type signed int short int long int unsigned unsigned int unsigned short int unsigned long int char signed char unsigned char float double long double