577 views
1 votes
1 votes
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

1 Answer

1 votes
1 votes

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.

Related questions

0 votes
0 votes
1 answer
1
TusharKumar asked Dec 22, 2022
524 views
can anyone explain how the for loop works here..?
0 votes
0 votes
2 answers
2
rohitkaushal1 asked Sep 22, 2022
494 views
What will be the output printed for find(4)? void find(int x) { static int i = 10, y = 0; y = y + i; for(i; i>0; i = i - 10) { if(x! = 0) find(x – 1); else printf(“%d...