Your browser doesn't support JavaScript The Basics - Windows Programming

The Basics

A simple piece of C code

#include <stdio.h>
int main()
{
/* my first program in C */
printf("Hello, World! \n");
return 0;
}

#include <stdio.h>

The first line of the program is a preprocessor directive which tells a C compiler to include the contents of file stdio.h. Include files contain additional information used by the program file during compilation. Stdio.h file stands for standard input-output header file and contains various prototypes and macros to perform input or output (I/O)

Main Function 

The main() function is where program execution begins and is required by every executable C program. Every function must include a pair of braces marking the beginning and end of the function. Within the braces are statements that make up the main body of the program

Program Comments

Any part of a program that starts with /* and ends with */ is called a comment and is ignored by the compiler.  Programmers use comments to explain their code but do these not affect the running of the code

Printf Statement

The printf() statement is a library function used to display information on-screen. In the example above, printf outputs the contents of the quotation marks followed by a new line \n.

The Return Statement

All functions in C can return values. The main() function returns a value and in this instance, the value 0 indicates that the program has terminated normally.  A nonzero value returned by the return statement tells the operating system that an error has occurred. 

Semicolons

In C, the semicolon acts as a statement terminator and indicates to the parser where a statement ends.  Several statements can be included on one line as long as each statement is terminated with a semicolon.