I'm getting started with C++ and have some questions about the variable types:
1)The size of a variable type, is it defined by the compiler or computer or both? and why it differ from one to another?
2)Isn't short int supposed to hold smaller data than int can hold and the same with int and long it, then why sometimes the sizez of data that both of them can hold(short int & int or int & long it) are equal ??
on my pc with Microsoft Visal C++:
cout<< "int: " <<sizeof(int) <<"\n"; cout<< "short int: " <<sizeof(short int) <<"\n";
both can hold 2 bytes only, then what's the point of having short int? the same applies to double & long double..both can hold the same size of data too.
3)For me, "unsigned long int" can hold 4 bytes, it's mentioned that maximum value it can hold is "4,294,967,295" what if I wanted to input a bigger number?what should I use?
4)For following code:
unsigned int c; cout <<"Enter c: "; cin >>c; cout <<c <<endl;
what does the program do when I enter I negative value ? I tried -1 and the output was:4294967295..how "-1" was processed? and why it didn't get refused by the program ?!!!
5)For the following code:
double c; cout <<"Enter C: "; cin>>c; cout <<c <<endl;
What does the program do when I enter a value bigger than it can hold ? I tried 1000000( one million) and the output was:"1e+006", how that value was processed ?
any help would be much appreciated :)