C Programming Language
Basics
Basics of C Programming?
C is a structured programming language. So every
instruction in a c program must follow the
predefined structure (Syntax).
C is also known as Function Oriented Programming
Language. So every executable statement must
written inside a function.
1
General Structure of a C Program
/* Documentation */
Pre-Processing Statements
Global Declarations
Main method
Used defined methods implementation
2
General Structure of a C Program
Documentation /* Documentation */
- It is used to provide brief information Pre-Processing Statements
of the program. Global Declarations
- This part is written using comments. Main method
- Generally the documentation part does Used defined methods
not executed by compiler & it is implementation
optional part.
3
General Structure of a C Program
Pre-Processing Statements
- It is used to link the header files, /* Documentation */
define the constants, etc... Pre-Processing Statements
Global Declarations
- Every preprocessor statement starts
with hash (#) symbol. Main method
- Every Preprocessor statement tells to Used defined methods
the compiler to perform required implementation
pre-processing before the actual
compilation.
4
General Structure of a C Program
Pre-Processing Statements
- Examples /* Documentation */
#include Pre-Processing Statements
#define Global Declarations
#undef
#ifdef
Main method
#ifndef
#if
#else Used defined methods
#elif implementation
#endif
#error
#pragma
5
General Structure of a C Program
Global Declaration
- This part is used to declare the /* Documentation */
variables which are common for multiple Pre-Processing Statements
methods. Global Declarations
- In this section, we also declare Main method
enumeration, structure, unions,
userdefined methods etc... Used defined methods
implementation
- It is also optional part. According to
our requirement we write this section.
6
General Structure of a C Program
Main method
- main method is the compulsory part for any c /* Documentation */
program. Pre-Processing Statements
- C language is a function oriented programming Global Declarations
language, so every c program must have at least
one function and that must be main. Main method
- Main is a userdefined method which specifies
the starting point of the program execution. Used defined methods
implementation
- Every c program execution starts with main
method and ends with main method itself.
7
General Structure of a C Program
Userdefined Methods
- In this section of the program we write the /* Documentation */
actual code for the userdefined methods. Pre-Processing Statements
- Userdefined methods can be implemented Global Declarations
either before or after the method.
Main method
- If it is implemented after the main then it
must be declared either inside or before the
main method. Used defined methods
implementation
- If it is implemented before the main then the
declaration can be ignored.
8
General Structure of a C Program - Example
/* Program to print a message Hello World! */
#include<stdio.h>
void main()
{
printf(“Hello World!!!!”);
9
Rules for Writing C programs
Every c program must contain exact one main
method
Every executable instruction must end with
semicolon (;)
All the system defined words (Keywords) must
be used in lowercase letters
Every open brace ({) must have the respective
closing brace (})
The variables must be declared in the
declaration section before they are used 10