I am learning C programming language and I stumbled on something while playing with some code. I was led to believe that an int has 4 bytes, and therefore has a maximum value of +2147483647(The problem was the long int). But when I tested that in my computer with GCC compiler, the result is different. I tried the same with long int, It gave the same maximum size. Can you please expain this behavior to me ? Other questions didn't help me understand the underlying reason. Let me add some examples I tried to find out what is happening.
Code sample:
#include <stdio.h>
#include <limits.h>
int main(void){
int a = 1, i;
printf("int limit: %d\n", INT_MAX);
printf("long int limit: %li\n", LONG_MAX);
for (i = 0; i < 10; i++){
a *= 10;
printf("A: %d\n", a); // To see when a is corrupted.
}
return 0;
}