Types in C++ Flashcards
Is C++ statically typed?
Yes
What does it mean for a lanuage to be statically typed?
Every variable, function argument and function return must be labeled with a type so the compiler knows how much memory to allocate, what type of values to store, what operations can be performed and how to interpret the bit patterns associated with the value.
What are the two catagories for types in C++?
Fundamental (built-in) types and derived (compound) types
List C++ built in types
Booleans (bool), Characters (char), Integers (int), Floating Point (float), Double Precision Floating Point (double), Valueless (void), Wide Char (wchar_t), std::nullptr_t
List C++ built-in type specifiers
short, long, signed, unsigned.
Where are type specifiers placed?
Before the type (unsigned int, for example)
What typical sizes are available for the int built-in type?
short int (16-bit), int (32-bit) long int (64-bit) - except windows which keeps it at 32-bit
Name the built-in integral types
int and char
What sizes are available to a char?
One byte (typically 8 bits, but not on all systems)
At Google, what can we assume about the sizes of ints and chars?
The char is 8-bits and the int is at least 32-bits. Within google3, we can assume a 32-bit int size with sizeof(int) = 4.
What is the default signed-ness of an int?
Signed, it is not common to write signed int
How does a signed int represent its numbers when it has N bits available?
Two’s compliment (-2^(N-1), 2^(N-1) - 1)
How does an unsigned int represent its numbers when it has N bits avaible?
(0, 2^N - 1)
Describe overflow behavior for signed and unsigned ints
For signed, it is unpredictable. For unsigned, it is predictable and acts similar to the modulo operator.
Describe conversion behavior from signed to unsigned ints
It is well defined,
What is the typical size of a bool?
One byte
What is the size of a char?
One byte