Skip to content

Instantly share code, notes, and snippets.

@scvalex
Created May 11, 2013 01:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scvalex/5558578 to your computer and use it in GitHub Desktop.
Save scvalex/5558578 to your computer and use it in GitHub Desktop.
A useful test for people who claim to know C: What does this program print? The answer requires a basic understanding of `stdio` and the semantics of forking. The answer is in the comments.
#include <stdio.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
printf("Hello, ");
fork();
printf(" World!\n");
return 0;
}
@scvalex
Copy link
Author

scvalex commented May 11, 2013

Build and run:

% gcc -Wall -o fork fork.c && ./fork 
Hello,  World!
Hello,  World!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment