Using a pointer
Following example shows how a pointer can be used to access the value in a variable.
int n=20,x; n x 20 garbage
1002 2000
int *ptr_n; /*uninitialized pointer*/ ptr_n garbage
1006
ptr_n=&n; /* store address of n in ptr_n */ ptr_n
1002
1006
*ptr _n = 30; /*modify value */ n
30
1002
Here we have accessed the contents of variable n using the pointer ptr_n. This can be done using the *operator.
*(ptr_n) => value at(ptr_n) => value at 1002 => 30
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
- 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