in Programming in C
573 views
1 vote
1 vote
What will be the output of following program:-

Size of int is 4 bytes

#incude<stdio.h>

int main()

{

    int a;

     for(a=1;a<=2147483647;a++)

               printf("%d\n",a);

 return 0;

}

 

 

a) will it print till its limit 2147483647

b) it will go to indefinate loop

c) compile time error
in Programming in C
573 views

4 Comments

No 0 to 2^n-1 i. e 2^32-1
0
0
Great thanks
0
0

unsigned int will have 0 to 232-1

0
0

1 Answer

1 vote
1 vote

With 4 byte integer size you can represent 231-1 = 2147483647 as the maximum positive integer. When your loop is at 2147483647, it will increment the counter, which will then become -2147483648 (-231 i.e., minimum value of integer of size 4B). This way, loop will be infinite.