Saturday 19 November 2022

Chapter 25 // Exercise 9 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 25 // Exercise 9

Without using any standard headers (such as <limits>) or documentation, compute the number of bits in
an int and determine whether char is signed or unsigned on your implementation.


So to print the number of bits in an int we know that sizeof() will return us the number of bytes in a type so you can just multiply that by 8. I don't think this is cheating as sizeof is a keyword in C++ and doesn't require any standard headers to be used. 

For the second part, I used the example from page 964. It shows that char is default signed on my machine.

No comments:

Post a Comment