Question: 1) Type in the following C program which prints the size of a char type, but duplicate the printf() line multiple times, changing it so
1) Type in the following C program which prints the size of a char type, but duplicate the printf() line multiple times, changing it so it also prints the size of types: unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, long long, unsigned long long, float, double, char*, and long*. Compile, run and record the results.
#include int main() { printf(sizeof char = %d , sizeof(char)); return 0; }
Note that the code for the following exercises may give compiler warnings. Normally you will want to fix your code so you don't get any warnings, as it usually indicates undesirable behavior (or at minimum it reveals tricky things that make your code harder to understand and verify).
2a) Write a short program which includes multiple lines similar to the following. The other lines should substitute the numbers 150, 150, 300, 1, and 65535. Run and record the results. Also give each result in 16bit binary. printf("%d\t%u ", (short)45, (unsigned short)45); 2b) Also, include multiple pairs of lines similar to the following, where c is declared as a char type. The other pairs of lines should substitute the values of 150, 150, 300, 1, and 65535. Run and record the results. Also give each result in 16bit binary. c = 45; printf("%d\t%d\t%u ", 45, (short)c, (unsigned short)c);
2c) Also, include multiple pairs of lines similar to the following, where uc is declared as an unsigned char type. The other pairs of lines should substitute the values of 150, 150, 300, 1, and 65535. Run and record the results. Also give each result in 16bit binary. uc = 45; printf("%d\t%d\t%u ", 45, (short)uc, (unsigned short)uc);
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
