In: Computer Science
Using C:
Implement function types that takes no input, declares 3 variables of type char, 3 of type short, 3 of type int, and 3 of type double---in that order---and prints the addresses of the 12 variables---in the same order---in both hex (use %p conversion instruction) and unsigned long format.
&a1 = 0x7ffd45e3ac0f, 140725776002063
&a2 = 0x7ffd45e3ac0e, 140725776002062
&a3 = 0x7ffd45e3ac0d, 140725776002061
&b1 = 0x7ffd45e3ac0a, 140725776002058
&b2 = 0x7ffd45e3ac08, 140725776002056
...
C CODE:
#include<stdio.h>
//function to print the address of the various types
variables
void types()
{
//3 character variables
char c1,c2,c3;
// 3 short int variables
short int s1,s2,s3;
// 3 int variables
int i,j,k;
//3 double variables
double p,q,r;
//printing the address of the above variables
//in hexadecimal and long unsigned int format
printf("&c1 = %#p ,%lu",&c1,&c1);
printf("\n&c2 = %#p ,%lu",&c2,&c2);
printf("\n&c3 = %#p ,%lu",&c3,&c3);
printf("\n&s1 = %#p ,%lu",&s1,&s1);
printf("\n&s2 = %#p ,%lu",&s2,&s2);
printf("\n&s3 = %#p ,%lu",&s3,&s3);
printf("\n&i = %#p ,%lu",&i,&i);
printf("\n&j = %#p ,%lu",&j,&j);
printf("\n&k = %#p ,%lu",&k,&k);
printf("\n&p = %#p ,%lu",&p,&p);
printf("\n&q = %#p ,%lu",&q,&q);
printf("\n&r = %#p ,%lu",&r,&r);
}
int main()
{
//calling the function types()
types();
}
SCREENSHOT FOR OUTPUT: