Write a short C program that declares and initializes (to any value you like) a double, an int, and a char. Next declare and initialize a pointer to each of the three variables. Your program should then print the address of, and value stored in, and the memory size (in bytes) of each of the six variables. Use the “%p” formatting specifier to print addresses in hexadecimal. You should see addresses that look something like this: "0xbfe55918". The initial characters "0x" tell you that hexadecimal notation is being used; the remainder of the digits give the address itself. Use proper formatting specifiers for char, int and double. Use the sizeof operator to determine the memory size allocated for each variable. Sample output from your program: The address of char ___ is 0x_______ The address of int ___ is 0x_______ The address of double ___ is 0x_______ The address of char* ___ is 0x_______ The address of int* ___ is 0x_______ The address of double* ___ is 0x_______ The value of char ___ is _______ The value of int ___ is _______ The value of double ___ is _______ The value of char* ___ is 0x_______ The value of int* ___ is 0x_______ The value of double* ___ is 0x_______ The size of char is _______ bytes The size of int is _______ bytes The size of double is _______ bytes The size of char* is _______ bytes The size of int* is _______ bytes The size of double* is _______ bytes
Write a short C program that declares and initializes (to any value you like) a
double, an int, and a char. Next declare and initialize a pointer to each of the
three variables. Your program should then print the address of, and value stored
in, and the memory size (in bytes) of each of the six variables.
Use the “%p” formatting specifier to print addresses in hexadecimal. You should
see addresses that look something like this: "0xbfe55918". The initial characters
"0x" tell you that hexadecimal notation is being used; the remainder of the digits
give the address itself. Use proper formatting specifiers for char, int and double.
Use the sizeof operator to determine the memory size allocated for each variable.
Sample output from your program:
The address of char ___ is 0x_______
The address of int ___ is 0x_______
The address of double ___ is 0x_______
The address of char* ___ is 0x_______
The address of int* ___ is 0x_______
The address of double* ___ is 0x_______
The value of char ___ is _______
The value of int ___ is _______
The value of double ___ is _______
The value of char* ___ is 0x_______
The value of int* ___ is 0x_______
The value of double* ___ is 0x_______
The size of char is _______ bytes
The size of int is _______ bytes
The size of double is _______ bytes
The size of char* is _______ bytes
The size of int* is _______ bytes
The size of double* is _______ bytes
Step by step
Solved in 4 steps with 2 images