Vous êtes sur la page 1sur 12

IT18111 – PROGRAMMING FOR PROBLEM SOLVING LABORATORY

EX.NO: 10 (A)
DATE: 15 - 11 - 2019

C PROGRAMMING WITH POINTERS

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:

Roll Number: 133 Page Number:


SOURCE CODE OR PROGRAM:

[cs19133@cslinux ~]$ vi 11a.c

#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);
}

SAMPLE INPUT AND OUTPUT:

[cs19133@cslinux ~]$ cc 11a.c


[cs19133@cslinux ~]$ ./a.out

Enter the value = 10

The Value 10 is in the pointer 000000000023FE44

RESULT:
A C program is written and the desired output has been achieved.

Roll Number: 133 Page Number:


IT18111 – PROGRAMMING FOR PROBLEM SOLVING LABORATORY

EX.NO: 10 (B)
DATE: 15 - 11 - 2019

C PROGRAMMING WITH POINTERS

QUESTION:
Swap three floating point numbers using pointers.

AIM:
To write a C Program to swap three floating point numbers using pointers.

ALGORITHM:

Roll Number: 133 Page Number:


SOURCE CODE OR PROGRAM:

[cs19133@cslinux ~]$ vi 11b.c

#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);
}

SAMPLE INPUT AND OUTPUT:

[cs19133@cslinux ~]$ cc 11b.c


[cs19133@cslinux ~]$ ./a.out

Enter three float values: 1.11 2.22 3.33

The Values before swapping: 1.110000 2.220000 3.330000


The Values after swapping: 2.220000 3.330000 1.110000

RESULT:
A C program is written and the desired output has been achieved.

Roll Number: 133 Page Number:


IT18111 – PROGRAMMING FOR PROBLEM SOLVING LABORATORY

EX.NO: 10 (C)
DATE: 15 - 11 - 2019

C PROGRAMMING WITH POINTERS

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:

Roll Number: 133 Page Number:


SOURCE CODE OR PROGRAM:

[cs19133@cslinux ~]$ vi 11c.c

#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);
}

SAMPLE INPUT AND OUTPUT:

[cs19133@cslinux ~]$ cc 11c.c


[cs19133@cslinux ~]$ ./a.out

Enter the value: 5

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.

Roll Number: 133 Page Number:


IT18111 – PROGRAMMING FOR PROBLEM SOLVING LABORATORY

EX.NO: 10 (D)
DATE: 15 - 11 - 2019

C PROGRAMMING WITH POINTERS

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:

Roll Number: 133 Page Number:


SOURCE CODE OR PROGRAM:

[cs19133@cslinux ~]$ vi 11d.c

#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:

[cs19133@cslinux ~]$ cc 11d.c


[cs19133@cslinux ~]$ ./a.out

Enter the values: 10 10


The product of the numbers 10 and 10 is 100.

RESULT:
A C program is written and the desired output has been achieved.

Roll Number: 133 Page Number:


IT18111 – PROGRAMMING FOR PROBLEM SOLVING LABORATORY

EX.NO: 10 (E)
DATE: 15 - 11 - 2019

C PROGRAMMING WITH POINTERS

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:

Roll Number: 133 Page Number:


SOURCE CODE OR PROGRAM:

[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);
}

SAMPLE INPUT AND OUTPUT:

[cs19133@cslinux ~]$ cc 11e.c


[cs19133@cslinux ~]$ ./a.out

Enter the three values: 10 20 30

Accessing through Single Pointer : 10 20 30


Accessing through Double Pointer : 20 30
Accessing through Triple Pointer : 30

RESULT:
A C program is written and the desired output has been achieved.

Roll Number: 133 Page Number:


IT18111 – PROGRAMMING FOR PROBLEM SOLVING LABORATORY

EX.NO: 10 (F)
DATE: 15 - 11 - 2019

C PROGRAMMING WITH POINTERS

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:

Roll Number: 133 Page Number:


SOURCE CODE:

[cs19133@cslinux ~]$ vi 11f.c

#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:

[cs19133@cslinux ~]$ cc 11f.c


[cs19133@cslinux ~]$ ./a.out

Printing the array through itself __________


1 2 3 4 5

Printing the array through pointers __________


1 2 3 4 5

RESULT:

A C program is written and the desired output has been achieved.

Roll Number: 133 Page Number:

Vous aimerez peut-être aussi