+ 1
What are the defaults? If you just state a variable int x; What is the default size and is it automatically signed or unsigned?
4 Respuestas
+ 3
It depends on the compiler implementation.
+ 2
If you just state int x; then it's default size will be 2 bytes in case of c++ bcoz it contains int data type and compiler to compiler the size of the data type varies.... If you assign value into the variable x according to that the compiler will identify whether it is signed or unsigned.
+ 1
An "int" means a "signed int". If you wan't that to be unsigned, you have to explicitly state that as "unsigned int".
Talking about the size of an int, this (and the sizes of most, if not all, primitive types) is not explicitly defined in the standard documentation. So you don't have any clue. It is in the hand of the compiler developers. However, as of now, all the compilers use 4 bytes to represent an int. But you can't blame anyone if some one in future make it 8 bytes long.
If you really worry about the size, use fixed width integer types (http://en.cppreference.com/w/cpp/types/integer).
However, as of my knowledge, these types are not defined in the standard. But they are available in all the popular compilers. However, if these types are available, then you know their exact sizes. (the code will break during compilation if these are not available. So you can/should use them when required without worrying about run-time complications)
0
It will take garpage value, its size is four bytes, and its type is signed integer.