This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(int argc, char** argv) { | |
static int i; | |
while(i<=10) | |
{ | |
(i>2)?i++:i--; | |
} | |
printf("%d\n",i); | |
return (EXIT_SUCCESS); | |
} |
2147483647
Explanation
i is an uninitialized static variable so its default value is zero
also i automatically promoted to unsigned int (because we did not specify if its signed or unsigned)
then 0<=10 condition true
inside while loop 0>2 false , i-- executed
second iteration i becomes 2147483647 (int size on my machine is 4 bytes)
2147483647 <=10 false , while loop is bypassed and 2147483647 is printed.