Sunteți pe pagina 1din 2

Computer Programming (Assignment - VIII): Pointers

1. What would be the output of the following programs:-


a) b)
#include<stdio.h>
main( ) #include<stdio.h>
{ main( )
int a = 5,b = 10,c ; {
int *p = &a ,*q = &b; int i=3, *j, k;
c=p–q; j = &i ;
printf("%d" , c) ; printf("%d\n", i**j*i+*j) ;
} }

c) d)
#include<stdio.h>
main() #include<stdio.h>
{ main()
int x=30, *y, *z ; {
y= &x ; int ***r, **q, *p, i=8 ;
/* Assume address of x is 500 and integer is 4 byte p = &i ;
size */ q = &p ;
r = &q ;
z = y; printf("%d, %d, %d\n", *p, **q, ***r);
*y++ = *z++ ; }
x++ ;
printf("x=%d, y=%d, z=%d\n", x, y, z);
}

e) f)
#include<stdio.h> #include<stdio.h>
main( ) main()
{ {
float a = 13.5 ; int i = 5 , j ;
float *b, *c ; int *p , *q ;
b = &a ; /* suppose address of a is 1006 */ p = &i ;
c=b; q = &j ;
printf ( "\n%u %u %u", &a, b, c ) ; j=5;
printf ( "\n%f %f %f %f %f", a, *(&a), *&a, *b, *c ) ; printf("%d %d", *p,*q) ;
} }

1
2. C program to print size of different types of pointer variables.

Hint:- Output depends on the system architecture, but each type of pointer will take
same memory space.

3. C program to add two numbers using pointers.

4. C program to print a string using pointer.

5. Program to read array elements and print with addresses using pointer.

6. C program to demonstrate example of double pointer (pointer to pointer).

S-ar putea să vă placă și