0% found this document useful (0 votes)
2 views6 pages

C Programs Using Pointers Explained

The document contains a series of C programs demonstrating various pointer concepts, including call by reference, pointer to pointer, and pointer to function. Each program includes code for specific tasks such as finding the factorial of a number, generating a multiplication table, finding the largest of three numbers, and swapping values. The programs utilize pointers to manipulate data and display results effectively.

Uploaded by

forfun5866
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

C Programs Using Pointers Explained

The document contains a series of C programs demonstrating various pointer concepts, including call by reference, pointer to pointer, and pointer to function. Each program includes code for specific tasks such as finding the factorial of a number, generating a multiplication table, finding the largest of three numbers, and swapping values. The programs utilize pointers to manipulate data and display results effectively.

Uploaded by

forfun5866
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

[Link] a C program to call by basic reference program.

#include<stdio.h>

#include<conio.h>

int main()

int x,y,*ptr;

x=10;

ptr=&x;

y=*ptr;

printf("%d %u %d %d %u %d %d %u
%u",x,&x,*&x,*ptr,ptr,y,&*ptr,&ptr,&y);

*ptr=25;

printf("%d \n",x);

getch();

2. Write a C program to display address of a pointer.

#include<stdio.h>

#include<conio.h>

int main()

int x,*p;

x=10;

p=&x;

p=p+1;

printf("%d %u %d %u",x,&x,p,&p);

getch();
}

3. Write a C program to declare a pointer to pointer variable and display


the content of these pointers.

#include<stdio.h>

#include<conio.h>

int main()

int i=3,*j,**k;

j=&i;

k=&j;

printf("%u %d %d %u %d %u %d %d %d
%d",&i,j,*k,&j,k,&k,i,*&i,*&i,*j,**k);

getch();

[Link] a C program to find factorial of a number using pointer to function


method.

#include<stdio.h>

#include<conio.h>

int fact(int *,int *);

int main()

int a,g;

printf("enter the number \n");

scanf("%d",&a);
fact(&a,&g);

printf("The factorial is %d",g);

getch();

int fact(int *n , int *x)

int i;

*x=1;

for(i=1;i<=*n;i++)

*x=*x*i;

5. Write a C program to generate a multiplication table of a number using


pointers.

#include<stdio.h>

#include<conio.h>

int mult(int *, int ,int *);

int main()

int n,i,k;

printf("enter the number whose table you desire\n");

scanf("%d",&n);

for(i=1;i<=10;i++){
mult(&n,i,&k);

printf("%d x %d=%d \n",n,i,k);

getch();

int mult(int *x,int i,int *f)

*f=(*x)*i;

6. Write a C program to find largest among three numbers using pointers.

#include<stdio.h>

#include<conio.h>

int large(int *, int *,int *, int *);

int main()

int a,b,c,l;

printf("Enter the three numbers\n");

scanf("%d",&a);
scanf("%d",&b);

scanf("%d",&c);

large(&a,&b,&c,&l);

printf("The greatest number among the three is %d ",l);

getch();

int large(int *x,int *y,int *z,int *lar)

int temp;

temp=(*x>*y?*x:*y);

*lar=(temp>*z?temp:*z);

7. Write a C program to swap numbers using pointers.

#include<stdio.h>

#include<conio.h>

int swap(int *, int *);

int main()

int a,b;

int *x,*y;

x=&a;
y=&b;

printf("Enter the two value of a and b \n");

scanf("%d",&a);

scanf("%d",&b);

printf("The values of a and b are %d and %d\n ",a,b);

swap(&a,&b);

printf("\nthe swapped value of a and b are %d and %d",a,b);

getch();

int swap(int *x,int *y)

int temp;

temp=*x;

*x=*y;

*y=temp;

You might also like