Created
September 14, 2012 02:36
-
-
Save theonewolf/3719473 to your computer and use it in GitHub Desktop.
static keyword C puzzle :-)
This file contains hidden or 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> | |
| #include <stdlib.h> | |
| #include <unistd.h> | |
| int static_puzzle() | |
| { | |
| static int i = 0; | |
| for (; i < 10; i++) | |
| { | |
| return i; | |
| } | |
| return i; | |
| } | |
| int static_puzzle2() | |
| { | |
| static int i = 0; | |
| for (; i < 10;) | |
| { | |
| return i++; | |
| } | |
| return i; | |
| } | |
| int main(int argc, char* argv[]) | |
| { | |
| int val; | |
| while ((val = static_puzzle2()) < 10) | |
| { | |
| fprintf(stdout, "%d\n", val); | |
| fflush(stdout); | |
| } | |
| sleep(5); | |
| while ((val = static_puzzle()) < 10) | |
| { | |
| fprintf(stdout, "%d\n", val); | |
| fflush(stdout); | |
| } | |
| return EXIT_SUCCESS; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment