2_Introduction to C-Programming
2_Introduction to C-Programming
Deepa R.YPage 1
Subject: Introduction to Algorithm
7) Speed: The compilation and execution time of C language is fast since there
are lesser inbuilt functions and hence the lesser overhead.
8) Pointer: C provides the feature of pointers. We can directly interact with the
memory by using the pointers. We can use pointers for memory, structures,
functions, array, etc.
Deepa R.YPage 2
Subject: Introduction to Algorithm
Character Set
A character set in C Programming Language is set all valid characters that can be
used to form words, numbers and expression’s in source programs
C- Tokens
The token is the smallest individual element in C. Tokens in C is the
most important element to be used in creating a program in C. In the C
language, the following 6 types of tokens are available:
1. Identifiers
2. Keywords
3. Constants
4. Operators
5. Special Characters
6. Strings
Keywords in C
A keyword is a reserved word. You cannot use it as a variable name, constant
name, etc. There are only 32 reserved words (keywords) in the C language.
Deepa R.YPage 3
Subject: Introduction to Algorithm
Identifiers
An identifier is used for any variable, function, data definition, labels in
your program etc.
Rules for naming identifiers
The rules that must be followed while naming the identifiers are as follows −
There is no rule on how long an identifier can be. We can run into
problems in some compilers, if an identifier is longer than 31 characters.
This is different for the different compilers.
A valid identifier can have letters (both uppercase and lowercase letters),
digits and underscores.
Deepa R.YPage 4
Subject: Introduction to Algorithm
Variable declaration
All the variables that we wish to use in the program need to be declared.
Meaningful names should be given to the variables. Variables can be declared
anywhere in the program according to their needs.
Syntax:
data-type variable-name;
In the above syntax a data-type is declared along with a variable name.
Multiple variables can also be declared in one statement but the data-type
has to be the same.
Deepa R.YPage 5
Subject: Introduction to Algorithm
Constants
The identifiers whose value do not/cannot change are known as Constants.
Variables can change their values but constants will never change their
value.
Types of constants
There are three types of constants:
1. Integer constants
An integer quantity which contains a sequence of digits is known as
an Integer constant. There are no decimal points.
3. Character constant.
They consist of a single character which is enclosed in single quotes.
Example: Character constant
'b' '@' '5'
The characters are stored by using the machines character set using the
ASCII code.
Constants declaration
Deepa R.YPage 6
Subject: Introduction to Algorithm
The const keyword tells us that the value of pi can never be changed.
Symbolic constant
For example,
#define printf print
#define MAX 50
#define TRUE 1
#define FALSE 0
Deepa R.YPage 7
Subject: Introduction to Algorithm
#define SIZE 15
Operators:
Operators are symbols that provide instructions for the
performance of various mathematical and logical operations. Operators are
tools that can alter data and variable values.
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Increment/Decrement Operators
5. Assignment Operator
6. Bitwise Operators
7. Conditional Operators
8. Special Operators
Deepa R.YPage 8
Subject: Introduction to Algorithm
Documentation
Link
Definition
Global Declarations
Main functions
Subprograms
Documentation Section
The documentation section is the part of the program where the
programmer gives the details associated with the program. He usually gives the
Deepa R.YPage 9
Subject: Introduction to Algorithm
name of the program, the details of the author and other details like the time of
coding and description. It gives anyone reading the code the overview of the
code.
Link Section
This part of the code is used to declare all the header files that will be used in
the program. This leads to the compiler being told to link the header files to the
system libraries.
Definition Section
In this section, we define different constants. The keyword define is used in this
part.
#define PI=3.14
2 int a=7;
Deepa R.YPage 10