C OVERVIEW
C is a programming language developed at AT & T's bell laboratory of USA in 1972. It was designed and written
by Dennis Ritchie. C is a general purpose programming language with lots of features. It is called middle level
language because it reduces the gap between high level language and low level language and at the same time
incorporating the best elements of high level language with the control and functionality of assembly language. As a
middle level language C allows the manipulation of bits and bytes & addresses-- the basic building elements with
which the computer functions. It provides a relatively good programming efficiency and relatively good machine
efficiency.
C is a structured programming language which allows variety of programs in small modules. Modular programming
reduces burden of debugging, testing and maintenance. The user is required to think of a problem in terms of
functions / modules. By combining different modules a complete program can be developed.
Features of C Language
1. Modularity:Ability to breakdown a large module into manageable sub modules.
2. Structured Programming Language:Use of sequence , decision and loops.
3. Free Form language:Program can start from any line, any column, can leave line spacing, column spacing
between any statements.
4. Portability: C requires little or no modification in source code when program is ported from one machine
to another machine.
5. Middle level language:Combines features of High and Low level language.
6. Extendibility:New modules can be added easily to expand the C application.
7. Flexibility:Use of number of keywords to suit any programming problem.
8. Case Sensitive:uppercase and lowercase are distinct.
C Character Set
A C program is a collection of number of instructions written in a meaningful order. Further instructions are made
up of keywords, variables, functions etc which uses the C character set defined by C. It is a collection of various
characters, digits and symbols which can be used in a C program. It comprises followings: Alphabets A-Z, a-z,
Digits:0-9 and Symbols given below:
Symbol Name Symbol Name Symbol Name
~ tilde > greater than + plus
< less than & ampersand * multiply
| or/pipe # hash % mod
greater than
>= <= less than equal ' single quote
equal
== equal = assignment >> right shift
!= not equal ^ caret . period
{ left brace } right brace + plus
right
( left parenthesis ) - minus
parenthesis
left square right square
[ ] / division
bracket bracket
backward
/ forward slash \ , comma
slash
: colon ; semicolon " double quote
_ underscore - minus << left shift
C Tokens
Smallest individual unit in a C program is called C Token. C defines six types of tokens.
1. Keywords: Keywords are those words whose meaning has already been known to the compiler. That is
meaning of each keyword is fixed. You can simply use the keyword for its intended meaning. You cannot
change the meaning of Keywords. Also you cannot use keywords as names for variables, function, arrays
etc. All keywords are written in small case letters. There are 32keywords in C.
2. Identifiers:Identifiers are names given to various program elements like variables, array, functions,
structures etc.
3. Constants:Constants in C refer to fixed values that do not change during the execution of a program. They
are also known as literals. There are various types of constants in C.
Integer Constant
Decimal: They are sequence of digits from 0 to 9 without fractional part. It may be negative, positive or
zero.
Octal: They have sequence of numbers from 0 to 7 and first digit must be 0. Example: 034,0,0564,0123
Hex: They have sequence of digits from 0 to 9 and A to F(represents 10 to 15).They start with 0x or 0X.
Example: 0x34, 0xab3, 0X3E.
Real Constants
They are the numbers with fractional part that is number with decimal point. They are also known as floating point
constants. Real constants are of two types: float and double. By default any floating point constant is double literal
and if you put f/F at the end of floating point literal it becomes float literal. Example: 34.56, 0.67, 1.23, 2.34f,
0.45F.
Real constants can also be represented in exponential or scientific notation which consists of two parts. For example
the number 212.345 can be represented as 2.12345e+2 where e+2 means 10 to the power 2. Here the portion before
the e that is 2.12345 is known as mantissa and +2 is the exponent. Exponent is always an integer number & e can
be written either in lower or upper case.
Single Character Constants
They are enclosed in single quotes. They consist of single character or digit. Example: '4', ’A', '\n'.Character
constants have integer value known as ASCII (American Standard Code for Information Interchange) values. For
e.g. ASCII value for A is 65.
String Constants
They are sequence of characters, digits or any symbol enclosed in double quotes. Example: "hello", "23 twenty
three”,"&^ABC”, "2.456"
Backslash Constants
C defines several backslash character constants which are used for special purpose. They are called so because each
backslash constant starts with backslash ( \ ). They are represented with 2 characters whose general form is \char but
treated as a single character. They are also called escape sequences. Given below is the list of backslash
character constants:-
ASCII
S.N BCC Meaning
Value
1. \b backspace 08
2. \f formfeed 12
3. \n newline 10
4. \r carriage return 13
5. \" double quotes 34
6. \' single quotes 39
7. \? question mark 63
8. \a alert 07
9. \t horizontal tab 09
10. \v vertical tab 11
11. \0 null 00
4.Special symbols
They are also known as separator and they are square brackets [ ] , braces { } , parentheses ( ) etc. The [ ] is used in
array and known as subscript operator, the symbol ( ) is known as function symbol.
Variables
A variable is a named location in memory that is used to hold a value that can be modified in the program by the
instruction. All variables must be declared before they can be used. They must be declared in the beginning of the
function or block.(except global variables) The general form of variable declaration is:
data type variable[list];
The [list] tells us that we can create multiple variables together separated by comma; [ ] represents optional
variable list.
Here list denotes more than one variable separated by commas;
Example:
int a; /* single variable declaration; a of int type*/
float b, c; /* multiple variable declaration; b and c of float type */
char p,q; /* multiple variable declaration; p and q of char type */
Here a is a variable of type int, b and c are variable of type float, and p, q are variables of type char. int ,
float and char are data types used in C. The rules for writing variables are same as for writing identifiers as a
variables is nothing but an identifier. Anything written in /* and */ is known as comment and ignored by the C
compiler.
First C Program
/ * Program Prints Hello C on the
screen */
#include<stdio.h>
main()
{
printf(" Hello C");
}
OUTPUT:
Hello C
We understand the first program in step by step manner
1. Whatever written inside /* and */ is treated as comment, and is ignored by the C compiler.
2. #include is the preprocessor directive.
3. stdio.h is the standard input output header file(due to .h extension) which is to be included in every C
program. There may be space between #include and <stdio.h>.
4. main() is a function due to symbol ( ) which is known as function symbol. This function must be present in
every C file you make because execution of your C program starts from this main().
5. { is the opening brace for main function and } is the closing brace.
6. All statements, instructions are written inside the main function inside { and }.
7. printf() is the inbuilt function ( pre built in C compiler) which prints whatever written inside " " on to the
screen.
8. C is case-sensitive programming language, so whatever you use that is in-built in C has to be in lower case.
9. The declaration of printf function is given in the header file stdio.h. Every statement in a C program has to
end with ; (semicolon).
Structure of a C program
The general structure of any C program is as given below. It simply states that a standard C program may look like
according to various sections presents in the structure. The first column in the table alone present the C program
structure. Second and third column are supplementary columns for better understanding of first column.
/*Demo program for C structure , does
Documentation used to put comments for the not serve any purpose except
program or program heading demonstration*/
(optional)
#include<stdio.h>
Header files Header file inclusion
#include<conio.h>
(required)
Symbolic Constants Declaration of symbolic #define PI 3.14
constants (optional) #define MAX 100
int x; float y; char z; /* global
Global variables, variables */
functions int sum(int,int); /* global function */
void show( ); /* global function */
main() /* main function definition
*/
{
printf(“Demo program \n”);
main( ) {…… } Your program executes from void demo() ; /* local function in
here (required) main */
………..
…..
show( );
}
int sum (int x,int y)
{statements;}
void show()
Global/local
Local /global function {statements;}
function definitions
definitions void demo()
{statements;}
Qualifiers
Qualifiers qualify the meaning of data types. unsigned, signed, short and long are the 4 qualifiers available in C.
The manner in which they are used as follows:
signed int x, y ,b ;
unsigned int p, q;
long int num;
short int n;
long int is a data type as mentioned earlier and short int is same as signed int or simply int on most of the C
compilers. signed qualifier is used where we want to work with both positive and negative
values. unsigned qualifier can be used where we want to work with only positive values. They can be used only
with char and integer data types. The available range increases in positive when we use unsigned say for example
range of signed char or simply char is -128 to 127 where as for unsigned char it is 0 to 255. Same holds
for int or long int.
Apart from these two important keywords are also used as qualifiers const and volatile. The const qualifier is used
to declare a variable as a constant for example const int x=10; declare a constant x of type int with constant value.
Use of volatile keyword is in the domain of embedded systems.
Format Specifiers
Format specifiers in C are used to display different types of data stored in variables or simply literals of various
types like integer, characters, floating point, strings etc. For every type of data C has a fix type of format
specifiers represented in the form of % followed by a character. All the format specifier are used
with printf and scanffunction. List of all format specifiers are shown in the table below:
S.N Data Type Format Specifier
1. int %d or %i
2. float %g or %f or %e
3. char %c
4. unsigned int %u
5. long int %ld
6. unsigned long int %lu
7. double %lf
8. long double %Lf
unsigned octal
9. %o
value
10. unsigned hex value %x or %X
11. unsigned int value %u
12. address %p
White Space Characters
Blank space, new line, horizontal tab, vertical tab, carriage return and form feed are known as white space
characters in C. During input of char, int , float or any other built in type scanf function ignores any white space
characters. The function printf recognizes all white space characters and interpret them. During reading of
strings scanf breaks at the first white space characters which may be space , tab or newline characters.
White space characters are called so as their purpose is same (make reading easier) as spaces appear between
words and lines on a printed page (as on this page). To improve the readability of a program white space
characters are used. Comments are also treated as white space characters by C compiler.