C Programming Fundamentals
C Programming Fundamentals
C is a fundamental language in the field of computer science. It is a high level language. It is both
specific purpose and general-purpose programming language created by Dennis Ritchie at the Bell
Laboratories-USA in 1972. It is a very popular language, despite being old.
C tokens:
The basic and the smallest units of a C program are called C tokens. There are six types of token in C.
1. Keywords: are reserve words, basically the sequence of characters that have one or more
fixed meanings, cannot be changed and must be written in lowercase letters. Like int, float ,
char, if , for, void, break, continue etc.
2. Identifiers: these are names given to the program elements such as variables, arrays and
functions. Rules for identifiers:
a. 1st char must be alphabet or underscore
b. All succeeding chars must be either letters or digits
c. Uppercase and lowercase identifiers are different in C
d. No special char or punctuation symbols are allowed except the underscore “_”.
e. No two successive underscore are allowed
f. Keywords should not be used as identifier
3. Constants: fixed value
4. Strings: more than one char
5. Operators: +, -, *, /, %, etc.
6. Special symbols: @, #, !, ~, ? etc.
Preprocessor Statements:
These statements begin with a # symbol and are also called pre-processor directives. These statements
direct the C pre-processor to include header files and also symbolic constants into a C program. Some
of the pre-processor statements are given below:
#include<stdio.h> - for the standard input/output functions
#include<conio.h> - for the console input/output
#include<string.h> - for inclusion of header file string
#include<math.h> - for inclusion of header file math
#include”Test.h” - for inclusion of header file Test
#include NULL 0 - for defining symbolic constant, NULL=0
Global Declaration:
Variables or functions whose existence is known in the main() function and other user defined functions,
are called global variables (or functions) and their declaration are called global declarations. This
declaration should be made before main() as shown in figure.
main():
as the name itself indicated this is the main function of every C program. Execution of C program starts
from main(). No C program is executed without main() function. It should be written in lowercase letters
and should not be terminated by a semicolon. It calls other library functions and user defined functions.
There must be one and only one main() function in every C program.
Braces:
Every C program uses a pair of curly braces { {. } }. The left brace indicates the beginning of main()
function. On the other hand the right indicated the end of main() function. The braces can also be used
to indicate the beginning and end of user defined functions and compound statements.
Declaration:
It is a part of the C program where all the variables, arrays, functions etc. used in the C program are
declared and may be initialized with their basic data types.
Statements:
These are instructions to the computer to perform specific operations. They may be input-output
statements, arithmetic statements, control statements and other statements. They also include
comments. Comments are explanatory notes on some instructions. The statements to be commented on
must be enclosed with /* and */ or //. Comment statements are not compiled and executed.
User- defined functions:
These are sub-program. Generally a subprogram is a function. And they contain a set of statements to
perform specific task. These are written by the users, hence the name user defined functions. They may
be written before or after main() function.
A simple C program is given below:
#include<stdio.h>
main()
{
printf(“ Welcome to C \n”);
}
Output:
Welcome to C
The first line tells the compiler to include standard i/o header file to perform reading and printing the
data. The 2nd line is the main(), the main function of a C program. The body of C program contains only
one statement i.e printf(“Welcome to C /”)
When the statement is taken for execution, main() calls the printf() and print() statement is included in
<stdio.h>. the printf() prints Welcome to C on the computer screen.
Compiling and executing a C Program
Compiling a C program means translating it into machine language. C compilers are used for this
purpose. The C program to be compiled must be typed in using the editor. An editor is a program which
allows the programmer to type in the program and then modify it. C compilers are available with and
without editors. The environment where you find the compiler, editor, debugging tools, linking
facilities, tracing and testing tools is called Integrated Development Environment (IDE).
Example: Turbo C (TC), Borland, C , Microsoft C/C++, and ANSI C
The procedures used in compiling and executing a C program differs from one operating system to
another. There are basically five steps in the successful execution of a program.
1. Creating a program file
2. Saving the program
3. Compilation
4. Linking system library function
5. Running (executing) program
Questions:
1. When and who developed C language?
2. What are C tokens?
3. Write a C program to print your name on the computer screen?
4. How do you make comments in your C program?
5. Explain steps involved in compiling and executing a C program