Array of pointers
C program having an array of three pointers which are assigned the addresses of three integer variables.
#include<stdio.h>
main()
{ int arr[3]={1,2,3};
int *ptr[3],i;
for(i=0;i<3;i++)
{ ptr[i]=arr+i; // assigning addresses of elements to array of pointers
}
for(i=0;i<3;i++)
{ printf(“\n address = %u value=%d”, ptr[i], *ptr[i]); }
}
Here output will be address of elements and its value.
Address = 3219018020 value=1
Address = 3219018024 value=2
Address = 3219018028 value=3
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
- Pointer to Array
- Pointer Arithmetic
- Types of Pointers
- Illustrate Basic Pointer Use
- Using Pointer
- Intializing Pointer
- Declaring Pointer
- Application of Pointers
- Value Model VS Reference Model
- What is Pointer
Comments
Post a Comment
Please give us feedback through comments