Getting started with C
Your first program, compiling it, and printing values.
C gives you direct control over memory and runs fast with very little overhead, which is why operating systems and device firmware use it. Learning it teaches you how a computer really works.
Save this as main.c, compile with gcc main.c -o main, and run ./main.
C
#include <stdio.h>
int main(void) {
printf("Vanakkam, C!\n");
printf("%d + %d = %d\n", 2, 3, 2 + 3);
return 0;
}Output
Vanakkam, C! 2 + 3 = 5
| Format | Prints |
|---|---|
%d | int |
%f | double, with %.2f for two decimals |
%c | char |
%s | A string |
%p | A memory address |