Home | API | MFC | C++ | C | Next

Programming With C

The Basics

A simple C program

#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 #include <stdio.h> is a preprocessor directive which tells a C compiler to include the contents of file stdio.h. This include file is a separate file that contains 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)

Int main 

The main() function is where the program execution begins and is required by every executable C program. Every function must include a pair of braces which mark 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 your program that starts with /* and ends with */ is called a comment and is ignored by the compiler.  Comments are used by the programmer to explain their code but do not affect the running of the code

Printf Statement

The printf() statement is a library function that displays information on-screen. In this instance, 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 itself returns a value and in this case, 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. 

Semicolon

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.


Home | API | MFC | C++ | C | Next
The Basics | Variables | Constants | Expressions and Operators | Controlling Program Flow | Input & Output | C++ Functions | Arrays | Characters and Strings | String Manipulation | Pointers | Structures | Unions | File Input and Output | Advanced Pointers | Type Conversion | Dynamic Memory Allocation

Last Updates:25 October 2022