world. I'm a very novice in CS and studying C with the book 'C Primer Plus'. There are review questions at the end of chapter 3 and I'm confused with some of their answers. I would like to clarify by my understanding of them. Please correct me and share some your knowledge.
So here are the questions from the book below, then my questions after.
6. Identify the data type (as used in declaration statements) and the printf() format specifier for each of the following constants: Constant Type Specifier -a. 12 int %d -b. 0X3 unsigned int %#x ... -d. 2.34E07 double %e -e. '\040' char(rlly int) %c -f. 7.0 double %f ... 7. the same as the question 6 but assume a 16-bit int: Constant Type Specifier -a. 012 unsigned int %#o ... -d. 100000 long %ld ... -g. 0x44 unsigned int %d
My questions:
Regarding 6-a & 7-a, how does adding 0 in front 12 need unsigned int to have more positive space in a 16-bit int system? 12 is 1100 in binary. 012 is mathematically the same but is it different in computing?
Regarding 6-b & 7-g, how come the hexadecimal formats have unsigned int? 0X3 and 0x44 are respectively 11 and 1000100 in binary, 3 and 68 in decimal. A 16-bit integer has possible values range from −32,768 to 32,767, but the both are unsigned int in the answers.
Regarding 6-d, I read in the book that the C standard provides a float has to be able to represent at least six significant figures. here 2.34E07 has more, so double. but also from the book, by default, the compiler assumes floating-point constants are double precision. Is this default rule only for constant? Do I need to be specific when assigning a variable?
Regarding 6-f, How come double for 7.0? is it because the compiler assumes floating-point constants are double precision? for variables should I use float like float f = 7.0; ?
Regarding 7-d, Is it long type(guarantees 32-bit) to have more space for 100,000? but we have to assume 16-bit int system, which is between 0 and 65,535 in an unsigned representation. How can a computer that has 16-bit int system handle more than what it is capable of?
Please feel free to tear me apart, shatter my understanding of data types in C and teach me.