Main Function
int main(void) {
return 0;
}The entry point of a C program.
C syntax quick reference: printf, pointers, structs, memory and compiling, based on cppreference. Every item below is clearly marked as a shortcut, command, or syntax reference.
int main(void) {
return 0;
}The entry point of a C program.
printf("%d %s\n", n, name);Prints formatted text.
#include <stdio.h>Includes a standard library header.
int n = 0;
double x = 1.5;
char c = 'a';Declares typed variables.
if (x > 0) {
...
} else {
...
}Runs code depending on a condition.
for (int i = 0; i < n; i++) {
...
}Loops a set number of times.
int add(int a, int b) {
return a + b;
}Defines a function with a return type.
int *p = &n;
*p = 5;Gets an address and dereferences it.
The entry point of a C program.
int main(void) {
return 0;
}Prints formatted text.
printf("%d %s\n", n, name);Includes a standard library header.
#include <stdio.h>Declares typed variables.
int n = 0;
double x = 1.5;
char c = 'a';Runs code depending on a condition.
if (x > 0) {
...
} else {
...
}Loops a set number of times.
for (int i = 0; i < n; i++) {
...
}Defines a function with a return type.
int add(int a, int b) {
return a + b;
}Gets an address and dereferences it.
int *p = &n;
*p = 5;Declares a fixed-size array.
int nums[5] = {1, 2, 3, 4, 5};Groups related fields.
struct Point {
int x, y;
};Allocates memory on the heap.
int *a = malloc(n * sizeof *a);Releases heap memory.
free(a);Compiles a C file into a program.
gcc main.c -o mainReads formatted input.
scanf("%d", &n);Defines a constant value.
#define MAX 100
const int LIMIT = 10;Branches on an integer value.
switch (n) {
case 1: ...; break;
default: ...;
}Repeats while a condition is true.
while (x < 10) {
x++;
}Common string functions from <string.h>.
strlen(s) strcpy(dst, src) strcmp(a, b)Gives a struct a short type name.
typedef struct { int x, y; } Point;Opens, writes and closes a file.
FILE *f = fopen("out.txt", "w");
fprintf(f, "hi\n");
fclose(f);It covers 20 common C patterns and examples, including Main Function, Print Formatted Output, Include a Header, Declare Variables, If / Else.
Yes. Each reference page includes a copyable code example.
Check the linked documentation for language or runtime version requirements. Libraries, file paths, terminal quoting and environment settings can differ across systems; no blanket platform compatibility is implied.