AnyCompiler

Your First C Program

Every C program needs a main function — int main() — which is where execution starts. #include <stdio.h> pulls in the standard I/O library, giving you access to printf. Returning 0 from main signals to the operating system that the program finished successfully.

Compiling happens first

When you hit run, the compiler (gcc) translates your entire file into machine code before a single line executes. If there's a type error or a syntax mistake anywhere, nothing runs at all — you get a compiler error instead of output.

Comments

Comments work like in most C-family languages (which borrowed this directly from C): anything after // on a line is ignored completely, existing purely so humans reading the code later understand why something is written the way it is.

Run it yourself

Here's a small program with a comment and two printf calls. This was actually executed to get the output shown below — try changing the text and running it yourself using the button under the example.

#include <stdio.h>

int main() {
    // This is a comment -- ignored by the compiler
    printf("Hello, world!\n");
    printf("Learning C one step at a time.\n");
    return 0;
}
Output
Hello, world!
Learning C one step at a time.

Next: variables and types — the primitive types, and how big each one actually is in memory.

Practice exercise

Add a comment above your code, then print "Learning C one step at a time."