Program shape
A C program starts in main. Include stdio.h when using printf, and return a status code from main.
#include <stdio.h>
int main(void)
{
printf("Hello, C!\n");
return 0;
}PRACTICAL C COURSE
Learn how C programs use data, functions, memory, and the standard library. Every topic includes a runnable example for Open Editor.
Practice method: type each example into Open Editor, predict its output, run it, then alter one input or condition and run it again.
A C program starts in main. Include stdio.h when using printf, and return a status code from main.
#include <stdio.h>
int main(void)
{
printf("Hello, C!\n");
return 0;
}Choose a type that describes the value, initialize variables, and make conditions easy to read.
for (int number = 1; number <= 5; ++number)
{
if (number % 2 == 0)
{
printf("%d is even\n", number);
}
}Functions make a program testable and reduce repeated logic. Give every function a declaration with clear parameter and return types.
int square(int value)
{
return value * value;
}C does not check array bounds automatically. Track the length and never index outside the valid range.
int scores[] = {72, 95, 81};
size_t count = sizeof scores / sizeof scores[0];A pointer holds an address. Dynamic memory from malloc must be checked and released exactly once with free.
int *score = malloc(sizeof *score);
if (score != NULL)
{
*score = 100;
free(score);
}Memory rule: initialize pointers, check allocation results, keep ownership obvious, and set freed pointers to NULL when they remain in scope.