This document provides examples of using pointers in C programming. It contains 11 programs that demonstrate different pointer concepts like passing pointers to functions, pointer arithmetic, arrays of pointers, and 2D arrays. The programs show how to declare and access variables using pointers, pass addresses of variables to functions using pointers, and traverse arrays using pointers. Pointers allow accessing and modifying values referenced by other variables in memory.
1. C Programming - Pointers
Organized By: Vinay Arora
Assistant Professor, CSED
Thapar University, Patiala
2. Program - 1
#include<stdio.h> void swapr(int x, int y)
#include<conio.h> {
void swapr(int,int); int t;
int main() t=x;
{ x=y;
int a=10,b=20; y=t;
clrscr(); }
printf("Value of variable a=%d and b=%d",a,b);
swapr(a,b);
printf("nValue of variable a=%d and b=%d",a,b);
getch();
}
Vinay Arora
CSED
4. Program - 2
#include<stdio.h> void swapr(int *x, int *y)
#include<conio.h> {
void swapr(int *, int *); int t;
int main() t=*x;
{ *x=*y;
int a=10,b=20; *y=t;
clrscr(); }
printf("Value of variable a=%d and b=%d",a,b);
swapr(&a,&b);
printf("nValue of variable a=%d and b=%d",a,b);
getch();
}
Vinay Arora
CSED
11. Program - 4
#include<stdio.h>
#include<conio.h>
void main()
{
int i, *x;
clrscr();
printf("Enter any Integer Valuet");
scanf("%d",&i);
x=&i;
printf("nx=Address value of in");
printf("nValue of x = %u",x);
x++;
printf("nAfter Increment in Pointern");
printf("Value of x = %u",x);
getch();
}
Vinay Arora
CSED
19. Program – 8 (Diff. notations for accessing Array)
#include<stdio.h> getch();
#include<conio.h> }
void main()
{
int num[]={24,34,12};
int i;
clrscr();
printf("Array Elements are");
for(i=0;i<=2;i++)
{
printf("n Value at arr[%d] is %d",i,num[i]);
printf("n Value at arr[%d] is %d",i,i[num]);
printf("n Value at arr[%d] is %d",i,*(num+i));
printf("n Value at arr[%d] is %d",i,*(i+num));
printf("n");
}
Vinay Arora
CSED