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
Also Read
- Static and Dynamic Memory Allocation
- Memory Leak and Dangling Pointer
- Memory Allocation for 2D Array
- Dynamic Memory Allocation
- Pointer Constant and Constant Pointer
- Pointer Declarations and their Meanings
- Functions and Pointers
- Initializing Pointer to Pointer
- Pointer to Pointer Multiple Indirection
- Relationship between Array and Pointer
- Pointer to Array
- Pointer Arithmetic
- Types of Pointer
- Illustrate Basic Pointer Use
- Using Pointer
- Declaring Pointer
- Application of Pointers
- Value Model VS Reference Model
- What is Pointer
Comments
Post a Comment
Please give us feedback through comments