Pointer to a Variable in C Programming

Notes:

Pointer to a Variable in C Programming Language:
- understand how to create a pointer which holds the address of another variable
- understand how to get or set the value of a variable at which a pointer is pointing

Declaring and initializing a pointer to a variable:

Syntax:
data_type *variableName = address of another memory location or NULL;
Ex:
int *iptr=NULL; // iptr is a pointer variable; which holds address of another integer type variable

Note: NULL indicates a pointer is not pointing to any memory location

Example Code:
#include <stdio.h>
int main()
{
int a = 0;
int *iptr = NULL;

printf("Value of a= %d\n",a);// Value of a= 0
printf("Address of a= %d\n",&a);// Address of a= 2293528
printf("\n");

iptr = &a; // assignment operation
printf("Value of iptr= %d\n",iptr);// Value of iptr= 2293528
printf("Value at iptr is pointing= %d\n",*iptr);// Value at iptr is pointing= 0
printf("\n");

*iptr = 10;
printf("Value at iptr is pointing= %d\n",*iptr);// Value at iptr is pointing= 10
printf("Value of a= %d\n",a);// Value of a= 10
printf("\n");

a = 20;
printf("Value of a= %d\n",a);// Value of a= 10
printf("Value at iptr is pointing= %d\n",*iptr);// Value at iptr is pointing= 20
return 0;
}