Illustrate basic pointer use
#include<stdio.h>
void main()
{
/*declarations */
int n=20,*ptr_n;
ptr_n=&n;
/* Displaying value*/
printf(“\n Direct access, value=%d”, n);
printf(“\n Indirect access, value=%d”, *ptr_n);
/*Displaying address */
printf(“\n\n Direct access, address=%u”, &n);
printf(“\n Indirect access, address=%u”, ptr_n);
/* Modifying value */
n=30;
/*Direct modification */
printf(“n\n Direct modification, value=%d %d”, n,*ptr_n); *ptr_n=50;
/*Indirect modification */
printf(“\n Indirect modification, value=%d %d”, n,*ptr_n); }
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
- 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