range of int

range of int is 0 to 32768
but my function is working for greater value ?
i mean if i give value>32768 to int x it is not giving any error WHY?

1
2
3
4
5
6
7
8
9
#include<iostream>
void myfun(int x){
int a=x
cout<<a;
}
int main(){
myfun(3276777);
return0;
}
The minimum guaranteed range of int is -32767 to 32767, but almost every platform today uses 2's complement 32-bit ints, which are -2,147,483,648 to 2,147,483,647. There are no limits to how large it can be.

But even if you exceed your platform's limits, you won't get an error message on most compilers.
Last edited on
Int could be larger depending on your compiler. It is compiler dependent you can check using std::numeric_size<int>::max(); Anyways it wont give you an error but more than likely a warning. You can just use a long if you want larger than a short however. ( most times long is the default for int so maybe a long long? ).
There is also short int or just short.
The table on this page gives typical ranges, but it it system dependent.
http://www.cplusplus.com/doc/tutorial/variables/
Topic archived. No new replies allowed.