Académique Documents
Professionnel Documents
Culture Documents
EX.NO: 10 (A)
DATE: 15 - 11 - 2019
QUESTION:
Declare an integer pointer variable, initialize and access the integer data through
the pointer variable.
AIM:
To write a C Program to declare an integer pointer variable, initialize and
access the integer data through the pointer variable.
ALGORITM:
#include <stdio.h>
main ()
{
int x;
printf ("\nEnter the value: ");
scanf ("%d",&x);
int *p=&x;
printf ("\nThe Value %d is in the pointer %p",*p,p);
}
RESULT:
A C program is written and the desired output has been achieved.
EX.NO: 10 (B)
DATE: 15 - 11 - 2019
QUESTION:
Swap three floating point numbers using pointers.
AIM:
To write a C Program to swap three floating point numbers using pointers.
ALGORITHM:
#include <stdio.h>
main ()
{
float x,y,z;
float t,*a,*b,*c;
printf ("\nEnter three float values: ");
scanf ("%f %f %f",&x,&y,&z);
a=&x;
b=&y;
c=&z;
printf ("\nThe Values before swapping: %f %f %f", *a, *b, *c);
t = *a;
*a = *b;
*b = *c;
*c = t;
printf ("\nThe Values after swapping: %f %f %f", *a, *b, *c);
}
RESULT:
A C program is written and the desired output has been achieved.
EX.NO: 10 (C)
DATE: 15 - 11 - 2019
QUESTION:
Write a C Program that creates the following structure and then read the integer
into variable a and print it using each pointer in turns.
s
q
t
a p
u
r
AIM:
To write a C Program that creates a structure and then read the integer into
variable a and print it using each pointer in turns.
ALGORITHM:
#include <stdio.h>
main ()
{
int a;
int *p;
int **q,**r;
int ***s,***t,***u,***v;
printf ("\nEnter the value: ");
scanf ("%d",&a);
p = &a;
q = r = &p;
s = t = &q;
u = v = &r;
printf ("\nThe value is %d.",a);
printf ("\nAccessing through Single Pointer: %d", *p);
printf ("\nAccessing through Double Pointer: %d %d", **q,**r);
printf ("\nAccessing through Triple Pointer: %d %d %d %d",
***s,***t,***u,***v);
}
The value is 5.
Accessing through Single Pointer : 5
Accessing through Double Pointer: 5 5
Accessing through Triple Pointer : 5 5 5
RESULT:
A C program is written and the desired output has been achieved.
EX.NO: 10 (D)
DATE: 15 - 11 - 2019
QUESTION:
Write a program that creates the structure shown in below figure and reads data
into a and b using the pointers x and y. The program then multiples the value of a by b
and stores the result in c using the pointers x, y, and z. Finally, it prints all three variables
using the pointers x, y, and z.
AIM:
To write a program that creates the structure shown in below figure and reads
data into a and b using the pointers x and y. The program then multiples the value of a
by b and stores the result in c using the pointers x, y, and z. Finally, it prints all three
variables using the pointers x, y, and z.
ALGORITHM:
#include <stdio.h>
main ()
{
int a,b,c;
int *x,*y,*z;
printf ("\nEnter the values: ");
scanf ("%d %d",&a,&b);
c= a*b;
x = &a;
y = &b;
z = &c;
printf ("\nThe product of the numbers %d and %d is %d",*x,*y,*z);
}
SAMPLE INPUT AND OUTPUT:
RESULT:
A C program is written and the desired output has been achieved.
EX.NO: 10 (E)
DATE: 15 - 11 - 2019
QUESTION:
Write a C Program to illustrate the initialization of a pointer in the structure.
AIM:
To write a C Program to illustrate the initialization of a pointer in the structure.
ALGORITHM:
[cs19133@cslinux ~] vi 11e.c
#include <stdio.h>
main ()
{
int a,b,c;
printf ("\nEnter the three values: ");
scanf ("%d %d %d",&a,&b,&c);
int *x=&a, *p=&b, *q=&c;
int **y=&p, **r=&q;
int ***z=&r;
printf ("\nAccessing through Single Pointer: %d %d %d",*x,*p,*q );
printf ("\nAccessing through Double Pointer: %d %d",**y,**r);
printf ("\nAccessing through Triple Pointer: %d ",***z);
}
RESULT:
A C program is written and the desired output has been achieved.
EX.NO: 10 (F)
DATE: 15 - 11 - 2019
QUESTION:
Accept an array with five variable and print it using pointers.
AIM:
To write a C program to accept an array with five variable and print it using
pointers.
ALGORITHM:
#include <stdio.h>
main ()
{
int a[5]={1,2,3,4,5},i;
printf ("\nPrinting the array through itself __________ \n");
for(i=0;i<5;i++)
{
printf ("%d \t",a[i]);
}
printf ("\nPrinting the array through pointer _________ \n");
for(i=0;i<5;i++)
{
printf ("%d \t",*(a+i));
}
}
SAMPLE INPUT AND OUTPUT:
RESULT: