Skip to content

Instantly share code, notes, and snippets.

@ramsey
Last active November 6, 2023 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 16 You must be signed in to fork a gist
  • Save ramsey/11072524 to your computer and use it in GitHub Desktop.
Save ramsey/11072524 to your computer and use it in GitHub Desktop.
Hello, World in C
#include <stdio.h>
int main()
{
printf("hello, world\n");
}
// Compile, then run `./a.out 1>stdout.txt 2>stderr.txt`
// Then run `echo $?`
// stdout.txt should contain "hello, world"
// stderr.txt should be empty
// Your `echo $?` command should return 0
#include <stdio.h>
int main()
{
printf("hello, world\n");
return 1;
}
// Compile, then run `./a.out 1>stdout.txt 2>stderr.txt`
// Then run `echo $?`
// stdout.txt should contain "hello, world"
// stderr.txt should be empty
// Your `echo $?` command should return 1
#include <stdio.h>
int main()
{
fprintf(stdout, "hello, world\n");
fprintf(stderr, "this is an error\n");
return 1;
}
// Compile, then run `./a.out 1>stdout.txt 2>stderr.txt`
// Then run `echo $?`
// stdout.txt should contain "hello, world"
// stderr.txt should contain "this is an error"
// Your `echo $?` command should return 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment