Create a procedural C++ program called datatype_sizes.cc that will output the si
ID: 3925217 • Letter: C
Question
Create a procedural C++ program called datatype_sizes.cc that will output the sizes in bytes of the datatypes long int, float, double and float *. Make your program simple and and its logic straightforward. For example, the program logic can consist solely of four printf() statements. . With the exception of warnings about parameters argc and argv of function main() not being used, your program must compile without errors or warnings when the -Wall and -Wextra options are given to the C++ compiler. Hint: use the C/C++ function sizeof(). The return type of sizeof() is size_t. To have printf(3) output a value of type size_t, use the “%zu” or “%zd” format specification.
Note: overly and unnecessarily complex programs may be docked marks.
Explanation / Answer
#include <stdio.h>
int main() {
printf("Size of long int = %zu ",sizeof(long int));
printf("Size of float = %zu ",sizeof(float));
printf("Size of double = %zu ",sizeof(double));
printf("Size of float* = %zu ",sizeof(float *));
}
/* sample output
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.