Dynamic memory allocation cannot be performed without using pointers, so it is necessary to learn a pointers.
A pointer is a variable which holds the address of the another variable.
Pointer is also declared as other variable declared, but it use a asterisk(*) symbol, to represent that it is a pointer.
Syntax:- data_types *variable_name;
Example:- int *p; // integer pointer
Note:- A pointer can hold the address of that variable, which is same as pointer data types,i.e data types of pointer variable=data types of other variable.
Every variable is a memory location, and every memory location has its own address which can be accessed by using ampersand(&) operator.
Program:- to print the address of a variable:
Use Pointer:-
A pointer is a variable which holds the address of the another variable.
Pointer is also declared as other variable declared, but it use a asterisk(*) symbol, to represent that it is a pointer.
Syntax:- data_types *variable_name;
Example:- int *p; // integer pointer
Note:- A pointer can hold the address of that variable, which is same as pointer data types,i.e data types of pointer variable=data types of other variable.
Every variable is a memory location, and every memory location has its own address which can be accessed by using ampersand(&) operator.
Program:- to print the address of a variable:
Use Pointer:-
- define a pointer variable
- assign the address of the other variable into pointer variable
- access the value at the address, from the pointer variable.It is done by using unary(*) operator.
Program 2:- using a pointer variable
NOTE:- A pointer assigned NULL is known as null pointer,that is this pointer variable having value 0
Comments
Post a Comment