Syntax Reference
Language Syntax Cheatsheet
All programming constructs across 35 languages & topics — with copy-able code examples. Pick a language and explore every construct.
18px
⚙️
C Programming
Batch 125 constructs
Basic skeleton of a C program — includes, main function, return value.
Program Structure
#include <stdio.h> // pulls in printf, scanf, fopen, fgets, etc.
#include <stdlib.h> // pulls in malloc, free, exit, atoi, qsort, etc.
#include <string.h> // pulls in strlen, strcpy, strcmp, memset, etc.
/* Multi-line comment —
ignored by the compiler */
// Single-line comment — also ignored by the compiler
int main(int argc, char *argv[]) { // argc = argument count; argv[] = argument strings
printf("Hello, World!\n"); // prints to stdout; \n = newline character
return 0; // 0 = success; any non-zero value = error
}💡 Code Explanation
- Every C program starts with #include directives that pull in standard library headers — stdio.h for input/output, stdlib.h for memory and utilities, string.h for string functions. The main() function is the entry point; the OS calls it when the program runs. argc holds the count of command-line arguments and argv[] is an array of those argument strings. printf() writes formatted text to stdout. Returning 0 from main signals success to the OS; any non-zero value signals an error. Comments (/* */ for multi-line, // for single-line) are stripped by the preprocessor before compilation.
🎓
Want to go deeper?
Explore our full interview Q&A library or enrol in a course to master these languages.