Exercise 1.Given the following piece
of code
int
i = 10;
char
c= 'A';
double
f = 25.5;
int
*iptr = &i;
char
*cptr = &c;
You are expected to display the result of
following statements in the given format.
Value of i
|
Address of i
|
Value of iptr
|
Address of iptr
|
Derefrenced Value of
*iptr
|
Size of iptr
|
Size of i
|
|
|
|
|
|
|
|
Value of c
|
Address of c
|
Value of cptr
|
Address of cptr
|
Derefrenced Value of
*cptr
|
Size of cptr
|
Size of c
|
|
|
|
|
|
|
|
Note: The format specifier for displaying address
of any data item is %x
SOURCE CODE:
#include<stdio.h>
void header()
{
printf("\n\n\n\t\tBuilt & Designed by Arslan Malik\n\n\t\t www.CWorldbyAS.blogspot.com\n\n\n");
}
int main()
{
int i=10;
char c='A';
double f=25.5;
int *iptr=&i;
char *cptr=&c;
header();
printf("\n\n\n\n\n\n");
system("pause");
system("cls");
printf("Value of i\tAddress of i\tValue of iptr\tAddress of iptr\t");
printf("\n\n %d\t\t %p\t %d\t %p ",i,&i,iptr,&iptr);
printf("\n\nDereferenced value of *iptr\tSize of iptr\tSize of i");
printf("\n\n\t %d\t\t\t %d\t %d",*iptr,sizeof(iptr),sizeof(i));
printf("\n\n");
printf("Value of c\tAddress of c\tValue of cptr\tAddress of cptr\t");
printf("\n\n %c\t\t %p\t %d\t %p ",c,&c,cptr,&cptr);
printf("\n\nDereferenced value of *cptr\tSize of cptr\tSize of c");
printf("\n\n\t %c\t\t\t %d\t %d",*cptr,sizeof(cptr),sizeof(c));
printf("\n\n");
return 0;
}
No comments:
Post a Comment