+ 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?

2nd Nov 2015, 4:51 PM
OTheB
OTheB - avatar
4 Answers
+ 3
It depends on the compiler implementation.
16th Jun 2016, 8:16 PM
VPA
VPA - avatar
+ 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.
2nd Feb 2017, 5:58 AM
Ashu Bagul
Ashu Bagul - avatar
+ 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)
16th Oct 2016, 6:52 AM
Sumudu
Sumudu - avatar
0
It will take garpage value, its size is four bytes, and its type is signed integer.
12th Apr 2016, 12:49 PM
Ahmad Naoum
Ahmad Naoum - avatar