Working with Pointers in C

Working with Pointers in C programming. A pointer is a variable whose value is the address of another variable, i.e., the direct address of the memory location.

Program Working with Pointer

Program

#include<stdio.h>
#include<conio.h>
void main()
{
int var = 20; //actual variable declaration.
int *ip; //pointer variable declaration.
ip = &var; //store address of var in pointer variable.
printf("Address of var variable: %x\n", &var);
              //address stored in pointer variable.
printf("Address stored in ip variable: %x\n", ip);
              //access the value using the pointer.
printf("Value of *ip variable: %d\n", *ip);
getch();
}
Output
Address of var variable: 19ff48
Address stored in ip variable: 19ff48
Value of *ip variable: 20

Program Assigning Name to Pointer and Printing

Program

#include<stdio.h>
#include<conio.h>
void main()
{
char *po = "HiLaLs Afridi"; //assigning Name to Pointer 'po'.
printf("Your Name is: %s", po); //and printing.
getch();
}
Output
Your Name is: HiLaLs Afridi

Program Printing Pointer Array Names

Program

#include<stdio.h>
#include<conio.h>
void main()
{   //assigning elements'Name' to 'arr' Pointer Array.
char *arr[4] = {"HiLaLs", "Khan", "Afridi", "Dara"};
for(int i = 0; i < 4; i++) //loop looping and
{
printf("%s", arr[i]); //printing Names.
printf("\n");
}
getch();
}
Output
HiLaLs
Khan
Afridi
Dara