Skip to main content

Initializing Pointers

Initializing Pointers 

Assigning an address to a pointer is called pointer initialization. Address of a variable must be stored in the pointer before it is used. This is done using the address-of (&) operator. 

Syntax


 pointer=&variable; 
Example: 
ptr=&n; //assign address of n to ptr 
 int a[10]; 
ptr=a; //assign base address of array a to ptr char str[10]=“ABCD”; 
 char *ptr =str; //the pointer ptr points to a string ABCD

Comments