Page 16 - Programming Microcontrollers in C
P. 16
Chapter 1
Introduction to C
Programming is a contact sport. Programming theory is interest
ing, but you must sit at a keyboard and write code to become a
programmer. The aim of this introductory section is to give you a
brief glimpse of C so that you can quickly write simple programs.
Later sections will revisit many of the concepts outlined here and
provide a more in-depth look at what you are doing. For now, let’s
start writing code.
Some Simple Programs
C is a function based language. You will see that C uses far more
functions than other procedural languages. In fact, any C program it
self is merely a function. This function has a name declared by the
language. In C, parameters are passed to functions as arguments. A
function consists of a name followed by parentheses enclosing argu
ments, or perhaps an empty pair of parentheses if the function requires
no arguments. If there are several arguments to be passed, the argu
ments are separated by commas.
The mandatory program function name in C is main. Every C pro
gram must have a function named main, and this function is the one
executed when the program is run. Examine the following program:
#include <stdio.h>
int main(void)
{
printf(“Microcontrollers run the world!\n”);
return 0;
}
1