Exercise
1: When variables
are declared, are they located in memory contiguously? Write a program with the
declaration: char a, b, c, *p, *q, *r;
And print out
the locations (addresses) that are assigned to all these variables by your
computer. Are the locations in order? If the locations are in order, are they
increasing or decreasing? Is the address of each pointer variable divisible by
4? If so, this probably means that each pointer value gets stored in machine
word. Double check the results using sizeof() for char and for char*. (Hint: if you want to
see addresses printed as decimal numbers rather than hexadecimals, it is usually
safe to cast an address as unsigned long and use the %lu format).
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()
{
char a,b,c;
char *p,*q,*r;
p=&a;
q=&b;
r=&c;
header();
printf("\n\n\n");
system("pause");
system("cls");
printf(" a = %lu ",&a);
printf("\n *p = %lu ",&p);
printf("\n b = %lu ",&b);
printf("\n *q = %lu ",&q);
printf("\n c = %lu ",&c);
printf("\n *r = %lu \n\n\n\n",&r);
return 0;
}
No comments:
Post a Comment