UNIT-2 History of C' Language

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 15

UNIT-2

History of ‘C’ language:


 ‘C’ is one of the most popular programming languages; it was developed by Dennis
Ritchie at AT & T’s Bell Laboratories at USA in 1972.

‘C’ IS A MIDDLE LEVEL LANGUAGE


 Low level language:
o Low level language is in terms of 0’s and 1’s.
o ‘C’ language has the certain features of “low-level language” that allows the
programmer to carry out operations on bits that are normally available in
assembly or
machine language.
 High level language:
o High level language looks like normal English, whose instruction set is more
compatible with human languages.
o These languages are machine independent. Ex are FORTRAN, PASCAL,
COBOL,
BASIC, C, C++,…..etc
 C stands in between these two categories. It is neither a low level language nor a high
 level language. It is a middle level language.
  It means it performs the task of low level language as well as high level language.
 We can write the codes for operating system, application programs, and assembly
 language programs in ‘C’ language.
 UNIX operating system is written in ‘C’ language.

FEATURES AND APPLICATIONS OF ‘C’ LANGUAGE:


1. ‘C’ is a general purpose, structured programming language.
2. ‘C’ is powerful, efficient, compact, portable and flexible.
3. ‘C’ is well suited for writing system software as well as application software.
4. ‘C’ program can be run on different operating systems of the different computers with
little or no alteration.
5. ‘C’ is a middle level language, i.e, it supports both the low level and high level
language features.
6. ‘C’ language allows manipulation of data at the lowest level i.e bit level manipulation.
This feature is extensively useful in writing system software program.
7. ‘C’ is a widely available, commercial ‘C’ compilers are available on most PC’s.
8. ‘C’ programs are fast and efficient.
9. ‘C’ has got rich set of operators.
10. ‘C’ can be applied in systems programming areas like compilers, Interpreters and
Assemblers etc.

STRUCTURE OF A ‘C’ PROGRAM


Documentation section
Preprocessor section
Definition section
Global declaration section
Void Main()
{
Declaration
part;
Executable
part;
}
Sub program section
{
Body of the sub program;
}
Documentation section:
 It contains a set of comment lines used to specify the name of program the author
and other details etc.,
Comments:
 Comments are very helpful in identifying the program features and underlying
 logic of the program.
  The single line comments using “\\”.
 The lines begins with ‘/*’ and ending with ‘*/’ are known as comment lines.
These are not executable, the compiler is ignored anything in between /* and */.
Preprocessor section:
 It is used to link system library files for defining the macros and for
defining the conditional inclusion.
Eg: #include<stdio.h>, #define A 10, #if def, #endif….etc.
Global declaration section:
 The variables that are used in more than one function throughout the program are
called global variables and declared outside of all the function i.e., before main().

 Main() Function:
 Every ‘C’ program must have one main() function, which specify the starting of
‘C’ program. It contains the following two parts.
Declaration part:
 This part is used to declare all the variables that are used in the executable part
of the program and these are called local variables.
Executable part:
 It contains atleast one valid ‘C’ statement.

 The execution of a program begins with opening brace ‘{‘and ends with closing
 brace ‘}’.
  The closing brace of the main function is the logical end of the program.
 All the statements in the program ends with a semicolon(;) except conditional and
control statements.

PROGRAMMING RULES:
  All statements in ‘C’ program should be written in lower case letters.


Blank spaces may be  inserted between the words. It is not used while declaring a variable, keyword,
 constant and function.

The  program statement can write anywhere between the two braces following the declaration
 part.

The user can also write one or more statements in one line separating them with a

semicolon(;).

EXECUTING A ‘C’ PROGRAM


 Execution is the process of running the program, to execute a ‘C’ program we
need to
follow the steps given below.
1. Creating the program.
2. Compiling the program.
3. Linking the program with system library.
4. Executing the program.
Creating the program:
 It means entering and editing the program in standard ‘C’ editor and save the
program with
.C as an extension.
Compiling the program:
 This is the process of converting the high level language
program into machine understandable form(Machine
 language). For this purpose compiler is used.
 Usually this can be done in ‘C’ language by pressing ALT+F9 or choose
 compile option in the menu system.
 Here there is a possibility to show errors i.e., syntax errors, means the
statements written in program are not in proper syntax.
Linking the program with system library:
 ‘C’ language program is the collection of predefined functions. These
functions are already written in some standard ‘C’ header files. Therefore
before executing a ‘C’ program, we need to link with system library. This can
be done automatically at the time of execution.
Executing the program:
 This is the process of running and testing the program with sample data.
At this time there is a possibility to show two types of errors given
below.
Logical errors: these are the errors, in which the conditional and control
statements cannot end their match after some sequential execution.
Data errors: these are the errors, in which the input data given, is not in a
proper syntax as specified in input statements.
Usually executing the program can be done by pressing CTRL+F9 or choose run option from the
menu system.

‘C’s CHARACTER SET


 The character set is the any language and they are used to represent information.

 Like natural languages, computer language will also have well defined
 character set, which is useful to build the programs.
 Thus learn to combine these alphabets to plan for words which in turn
are combined to form sentences and sentences are combined to form
 paragraphs.
 Similarly the characters used to write ‘C’ program are basically of two types,
namely
i. Source character set
ii. Execution character set
Source character set
 These are used to construct the statements in the source program.
 These are of four types
Source character Notation
set
Alphabets A to Z and a to z
Decimal digits 0 to 9
White spaces Blank space, horizontal tabs, vertical tab, new line, form feed.
Special characters +, -, *, /, ;, ~, < , > , {, }, =, @, % .

Execution character set:


 These are employed at the time of execution. This set of characters are
also called as non graphic characters because, these characters are
 invisible and cannot be printed or displayed directly.
 These characters will have effect only when the program is being executed.
 Execution characters set are always represented by a backslash(\) followed by a
character.
 These are also called as ‘escape sequences’.
Character Escape sequence Result
Bell(Alert) \a Beep sound
Backspace \b Moves previous position
Horizontal tab \t Moves next horizontal tab
Vertical tab \v Moves next vertical tab
New line \n Moves next line
Form feed \f Moves initial position of next page
Carriage return \r Moves beginning of the line

C TOKENS:
 The tokens are usually referred as individual text and punctuation in a passage of text.

 The ‘C’ language program can contain the individual units called the C tokens and
has the following types.
1. Identifiers
2. Keywords
3. Constants
4. Strings
5. Operators
6. Special symbols

1. IDENTIFIERS
 Identifiers are names given to various program elements, such as variables, functions
and arrays etc.
Rules:
 Identifiers consist of letters and digits in any order.
  The first character must be a letter/character or may begin with underscore( _ ).
 Both upper/lower cases are permitted although uppercase character is not
 equivalent to corresponding lowercase character.
 The underscore ‘ _’ can also be used and is considered as a letter.

 An identifier can be of any length while most of the ‘C’ compiler recognizes only the
 first 31 characters.
  No space and special symbols are allowed between the identifier.
 The identifier cannot be a keyword.
Valid identifiers:
STDNAME, SUB, Y2K.
Invalid identifiers:
STD NAME, Return, $stay, 7rno.

2. KEYWORDS:
 There are certain reserved words called keywords that have standard and predefined
meaning in ‘C’ language which cannot be changed and they are the basic building
 blocks for program statements.
 Keywords are must written in lower case.
 The ‘C’ keywords are listed below.
1. auto 9. double 17. int 25. struct
2. break 10. else 18. long 26. switch
3. case 11. enum 19. register 27. typedef
4. char 12. extern 20. return 28. union
5. const 13. float 21. short 29. unsigned
6. continue 14. for 22. signed 30. void
7. default 15. goto 23. sizeof 31. volatile
8. do 16. if 24. static 32. while

Data types:
Data type is the type of the data, that are going to access within the program.

 Each data type may have predefined memory requirement and storage
representation.
Primary User defined Derived Empty
char structures Arrays
int union pointer void
float typedef
double

The bytes occupied by each of the primary data types are


Data type Description Memory Control Ex
string
int Integer quantity 2 bytes %d int a=39;
char Single character 1 byte %c char s = ‘n’;
float Floating pointing no’s. 4 bytes %f float f=29.77
double Double floating pointing 8 bytes %lf double d=
no’s. 29771770776
 All C compilers supports the five fundamental data types called int, char, float,
 double and void.
 The primary data types are divided into the following.
INTEGER TYPE
 Integers are the numbers with the supported range.
 Usually the integers occupy one word of storage typically 16 or 32 bits.
 The size of the integer depends upon the system.
signed unsigned
int unsigned int
short int unsigned short int
long int unsigned long int
CHARACTER TYPE
 Characters are generally stored in 8 bits and a single character can be defined as
char data type.
char signed char unsigned
FLOAT TYPE
 The floating point numbers are generally stored in 32 bits with the 6 digits of
precision.
 The double datatype uses the 64bits with the 14 digits of precision.
float double long double
EMPTY DATA TYPE
  The void is the null data type in ‘C’ language.
 This is generally specified with the function which has no
arguments. void
VARIABLES:
 A variable is an identifier that is used to represent some specified type of
information.
  Variable name give to relate the program.
i) Variable declaration:
 We must declare them in a program, and this declaration tells the compiler
what the variable name and type of the data that the variable will hold.
Syntax: datatype variable-1,variable-2,…,variable-n;
Example: int code; char sex; float price;
ii) Initializing variables:
 Initialization of variables can be done using the assignment
 operator ( = ). Syntax: Datatype Variable = value;
Example: int i=29;

SCOPE OF VARIABLES:
Local variables:
 The variables which are defined inside a main function block or inside a
 function are called local variables.
 It is declared within blocks.
Examp
le: void
main()
{
int i,j;
/* body of the function */
}
Global variables:
 The variables that are declared before the function main() are called the global
variables.
Exampl
e: int
a=5,b=2
; void
main()
{
fun();
}
void fun()
{
int
sum;
sum =
a+b;
}

STORAGE CLASSES:
1. Auto:
 They are called as the automatic because their memory space is automatically
 allocated as the variable is declared.
 It is optional keyword.
Syntax: Storage_class_type data_type var1, var2……var n;
Example: auto int a,b;
2. Static:
 The static variables are the variables for which the contents of the variables
 will be retained throughout the program.
 These are permanent within the function in which they are declared.
Syntax: Storage_class_type data_type var1, var2,…….varn;
Example: static int a,b;
3. Extern:
 The external variables are declared out of the main() function the availability of these
variables are throughout the program and that is both in main program and inside the
user
defined functions.
Syntax: Storage_class_type data_type var1, var2,……var n;
Example: extern int a, b;
4. Register:
 Registers are special storage areas within a computer’s central processing unit.

 The actual arithmetic and logical operation that comprise a program are carried
out within these registers.
Syntax: Storage_class_type data_type var1, var2, ………..var n;
Example: register int a,g;

CONSTANTS:
 The item whose values cannot be changed during the execution of program are
 called constants.
a) Numeric constants:
i) Integer constants:
 An integer constant formed with the sequence of digits.

 There are three types of integer constants which forms different number
 system. Syntax: const datatype identifier=value;
 Example: const int M = 95;
Rules:
  It must have atleast one value.
 Decimal point is not allowed.
  It can be either positive or negative.
ii) Real constants:
 A real constant is made up of a sequence of numeric digits with presence of a
 decimal point.
 Real constants serve as represent quantities such as distance, heights,
 temperatures, etc. Syntax: const datatype identifier=value;
 Example: const float distance =126.5;
Rules:
 A real constant must have one digit.
 A real constant must have decimal point.
 No commas or blank spaces are allowed.
b) Character constants:
i) Single character constants:
 The character constant contains a single character enclosed within pair of single
inverted commas(‘) both pointing to the left.
Syntax: const datatype identifier= value;
Example: const char
c=’s’,gender=’F’; ii) String
constants:
 A string constant is a sequence of characters enclosed in double quotes the
characters may be letters, numbers, special characters and blank spaces etc.
Syntax: const datatype identifier= value;
Example: const char c[10]=”senthil”;

Delimiters:
These are the symbols, which has some syntactic meaning and has got significance.
Symbol Name Meaning
# Hash Pre-processor directive
, Comma separate list of variables
: Colon Label
; Semi colon Statement end
() Parenthesis Function and Expression
{} Braces Creating blocks
[] Square bracket Arrays

Statements:
 Statements can be defined as set of declaration or sequence of action. Statement
 causes the computer to perform some action.
1. Assignment statements:
 Assignment operator used for assigning values to the variables.
Example: basic =3890;

2. Null statements:
 A statement without any characters and it has only semicolon is called null statement
Example: ; (null statement)
3. Block of statements:
 Block contains several statements that are enclosed within a pair of braces {}.
 These can be any of expression, assignments and keywords etc.
Example:
{
int
a=890;
float b=
89.9;
printf(“%d%f”, a, b);
}
4. Expression statements:
  These consist of expressions and can be arithmetic, relational or logical.
Exampl
e: a=
29
B=a
+77;
fun(
a,b);

OPERATORS
 An operator is as symbol that specifies an operation to be performed on the operands.
 The data items are called operands.
Example: a+b
‘+’ operator and a, b are the operands.
Types of operators:
1) Arithmetic Operator (+, -,*,/,%,)
2) Relational Operator (<,>,<=,>=,!=,==)
3) Logical Operators (&&.||,!)
4) Assignment Operator ( = )
5) Increment & decrement Operator (++,--)
6) Conditional (or) Ternary Operator (? , : )
7) Bitwise Operator (&,!,|,^)
8) Special Operator (, sizeof,&&*, .&->)
1) Arithmetic operators:
 Basic arithmetic operation like addition, subtraction, multiplication, and division.
Operator Meaning Example A=9, B=5
+ addition C=a+b C=14
- subtraction C=a-b C=4
* multiplication C=a*b C=45
/ division C=a/b C=1
% Modulo C=a%b C=4

Unary arithmetic: it requires only one operand.


Ex: +x
Binary arithmetic: it requires two operands.
Ex: a+b

2) Relational operators:
 Relational operators are used to compare two or more operands.
 Operands may be variables, constants or expression.
 The value of relational expression is either one or zero.
 Relational operators are used in decision making process.
Operator Meaning Example A=9, B=5
< Less than C=a<b C=0
> Greater than C=a>b C=1
<= Less than or Equal to C=a<=b C=0
>= Greater than or equal to C=a>=b C=1
== Equal to C=a==b C=0
!= Not equal to C=a!=b C=1

3) Logical operators:
 Logical operators are used to combine the results of two or more conditions.
 The logical operators are &&, ||,!
Syntax: (exp1)&&(exp2)
Operator Meaning Example A=9, B=5, C=2
&& Logical AND d=(a>b)&&(a>c) d=1
|| Logical OR d=(a>b)||(a>c) d=1
! Logical NOT d=!(a>=b) d=0

4) Assignment operators:
 Assignment operators are used to assign a value or an expression or a value of a
variable to another variable.
Example: x=5;
i) Compound assignment:
 Compound assignment operators to assign a value to a variable in order to assign a
new value to a variable after performing a specified operation.
Example: x+ = y
ii) Nested assignments:
  ‘C’ language has got distinct features in assignment called nested assignment.
Syntax:
 var1=var2=…………..var-n= single variable or expression or value;
Example: i=j=k=l;
x=y=z=(i+j
+k);

5) Increment or decrement operators:


 ++ and -- are the increment and decrement
operator.  These operators are called unary
operators.
 Pre increment or pre decrement: First increment or decrement the value after
assign or operate.
 post increment or post decrement: Assign or operate after increment or decrement
Operator Meaning Example A=5
++a Pre increment printf(“A=%d”,++a) A=6
--a Pre decrement printf(“A=%d”,--a) A=5
a++ Post increment printf(“A=%d”,a++) A=5
a-- Post decrement printf(“A= %d”,a--) A=5

6) Conditional operator:
 It checks the condition and executes the statement depending on the condition.
 It is like as if…else statement.
Syntax:
Condition?exp1:exp2;
Example:
int a=5,b=3,big;
big=a>b?a:b;
printf(“%d is big”,big);

7) Bitwise operators:
 It is used to manipulate the data at bit level.
It operates on integer only.

 It may not be applied to float or


real. a) Bitwise AND(&):
 This operator is represented as ‘&’ and operates on two operands of integer type.
 Truth table for &:
A B A&B
0 0 0
0 1 0
1 0 0
1 1 1
b) Bitwise OR(|):
 This operator gives if either of the operand bit is ‘|’ then result is ‘1’ or both operands
are 1’s then also given ‘1’.
A B A|B
0 0 0
0 1 1
1 0 1
1 1 1
c) Bitwise exclusive OR(^):
 Similar to AND operator in all aspects but integer gives if either of the operand bit is
high(1) then it gives high(1) result.
 If both operand bits are same then it gives
low(0) result.

For all the above operators in all possible combinations of bits as shown below.
A B A|B A&B A^B ~A
0 0 0 0 0 1
0 1 1 0 1 1
1 0 1 0 1 0
1 1 1 1 0 0

8) The special operator:


1. Comma operator(,):
 It is used to separate the statement elements such as variables, constants or
expression etc.
Example: val = (a=3, b=9, c=77, a+c);
2. Sizeof() operator:
 it is a unary operator, that returns the length in bytes of the specified variable, and
it is very useful to find the bytes occupied by the specified variable in the
 memory.
 It is a compile time operator.
Syntax:
sizeof(var);

3. Pointer operators:
&---This symbol specifies the address of the variable.
* --- This symbol specifies the value of the variable.
4. Member selection operators:
. and -- > : These symbols used to access the elements from a structure.

EXPRESSIONS:
 An expression represents data item such as variables, constants and are
 interconnected with operators as per the syntax of the language.
 An expression is evaluated using assignment operator.
Syntax: variable = expression;
Example: x=a*b-c;

Arithmetic operator’s precedence:


 Arithmetic operators are evaluated from the left to right using the
precedence of operators when the expression is written without the
 parameters.
High:* / %
Low: + -
 First phase: the highest priority operators are evaluated in the expression.
 Second phase: the lowest priority operators are evaluated in the expression.

Type conversion:
 It refers to the process of changing an entity of one data
 type into another. i) Implicit conversion:
 It is an automatic type conversion. In a mixed type expression data of one
or more subtypes can be converted to a super type as needed at runtime so
that the program will run correctly.
E
x
a
m
p
l
e
:

i
n
t

c
;
f
l
o
a
t

f
=
3
.
5
;

c
=
f
;

p
r
i
n
t
f
(

%
d

,
c
)
;
OUTPUT:
3
ii) Explicit conversion:
 The explicit conversion can be made possible to convert one data
type to another by forcefully and it is different from the implicit
conversion.
Syntax: var1=(datatype)var2;
Ex:
int a=10;
float(a);
Where a=10;
float (a) will contain 10.000000

MANAGING INPUT AND OUTPUT OPERATIONS


INPUT OUTPUT STATEMENTS
 We know that input, process, output are the three essential features of computer
program.
 The program takes some input data processes it and gives the output.
 We have two methods for providing data to the program.
o Assigning the data to the variables in a program.
o By using the Input/Output statements.
 In ‘C’ language, two types of Input/Output statements are available, and all
 input and output operations are carried out through function calls.
 Several functions are available for input/output operations in ‘C’.
 These functions are collectively known as the standard I/O library.
i) Unformatted Input/Output statements
ii) Formatted Input/Output statements
Input / Output

Unformatted I/O Formatted I/O

Input Output Input Output


getchar() putchar() scanf() printf()
getc() putc() fscanf() fprintf()
WWW gets() M puts()
getch()
getche()

UNFORMATTED INPUT/OUTPUT STATEMENTS


1) getchar() function:
 A single character can be given to the computer using ‘C’ input library function
getchar().
Syntax:char variable = getchar();
Example: char x;
x= getchar();
 The getchar() function is written in standard I/O library.
  It reads a single character from a standard input device.
 This function do not require any arguments, through a pair of empty
 parenthesis, must follow the statement getchar().
2) putchar() function:
 The putchar() function is used to display one character at a time on
the standard output device.
Syntax: putchar(char variable);
Example
:char x;
putchar(x
);
3) getc() function:
 This is used to accept a single character from the standard input to a
 character variable. Syntax: char variable = getc();
Examp
le: char
c; c=
 getc();
4) putc() function:
 This is used to display a single character in a character variable to
 standard output device. Syntax: putc(char variable);
Exam
ple:
char
c;
putc(c
 );
5) gets() function:
 The gets() function is used to read the string from the standard input device.
Syntax: gets(char type of array variable);
Example: gets(s);
6) puts() function:
 The puts() function is used to display/write the string to the standard output
 device(Monitor). Syntax: puts(char type of array variable);
 Example:puts(s);
7) getch() function:
 The getch reads a single character directly from the keyboard without
 echoing to the screen. Syntax: int getch(void);
8) getche() function:
 The getche reads a single character from the keyboard and echoes it
to the current text window.
Syntax: int getche(void);
Character test functions:
Function Test
isalnum(ch) Is ch an alphanumeric character?
isalpha(ch) Is ch an alphabetic character?
isdigit(ch) Is ch a digit?
Is ch a lowercase letter?
islower(ch)
toupper(ch) Convert ch to uppercase.
isupper(ch) Is ch a uppercase letter?
isspace(ch) Is ch a blank space character?
tolower(ch) Convert ch to lowercase.

FORMATTED INPUT/OUTPUT STATEMENTS:


 Formatted input/output refers to input and output, that has been arranged in a
particular format.
INPUT OUTPUT
scanf() printf()
fscanf() fprintf()
a) scanf() function:
 Input data can be entered using the standard input library function called scanf().
 This function is used to enter any combination of input.

 The scanf() function is used to read information from the standard input device, scanf()
starts with a argument and may contain additional arguments.
Syntax: scanf(“control string”, &var1,…………&var-n);
Example: int n;
scanf(“%d”,
&n);
Control string:
 It is the type of data to accept via the input statements, this can be formatted and
always preceded with a ‘%’ sign.
Format code Meaning
%c Single character
%d integer
%s Strings
%f Float values
Rules:
 The control string must be preceded with % sign and must be within quotations.

 If there is a number of input data items, items must be separated by commas and
 must be preceded with & sign except for string input.
 The control string and the variables going to input should match with each other.
  It must have termination with semicolon.
b) printf() function:
 Output data or result of an operation can be displayed to a standard output device
 using the library function printf().
 This function is used to output any combination of data.
 It is similar to the input function scanf(), except that it display data rather than input.
 There are two types of printf() functions:
1. printf() with control string
2. printf() without control string
Syntax: printf(“control string”, var1,
var2,…………var n); Example: printf(“result
is…….%d”, n);
printf(“%f”,f);
printf(“%s”,s);
Rules:
 The variable must be separated by commas, and need not be preceded with ‘&’ sign.
 The control string and the variables must match in their order.
 The control string must be in quotations and there also use any other text to print with
data.
 Provide blank space in between the numbers for better readability.

 Print special messages wherever required in


output. fscanf() and fprintf():
 fscanf() and fprintf() functions are used only during the file operations.
 fscanf()---for reading the content from file.
 fprintf()---for writing the content to the file.

Reading and writing integer numbers:


 The integers can be read/write through the scanf() and printf() statements with the
field specification along with the control string.
Reading:
  The scanf() function reads the integer numbers using its format specification ‘%d ’
Syntax: scanf(“%d” , &var);
Example: scanf(“%d%d”, &x,
 &y);
 Writing:
 The integer data values can also be displayed using the field width
specification in printf() statement.
Syntax: printf(“%d”, var);
Example: printf(“%d”, x);

Reading and writing real or floating point


numbers: Reading:
 The scanf() function reads the real numbers using its format specification
‘%f ’ Syntax: scanf(“%f” , &var);
Example: scanf(“%f%f”, &x, &y);
Writing:
 The writing or displaying of real numbers may be displayed in decimal point
notation using the field width specification.
Syntax: printf(“%(width)f” , var);
Example: printf(“%.2f”,x);

Reading and writing character strings:


 The single character or string can be read/write through the scanf() and
printf() statements with the field specification along with the control
string.
Reading a character:
 The specification for reading character is %c
Syntax: scanf(“%c”, var);
Example: scanf(“%c”, gender);
Reading strings:
  Specification for reading string is %s
Syntax: scanf(“%s”, var);
Example: scanf(“%s”,
 name);
Writing a character:
 A single character can be displayed in a desired position using the following format.
Syntax: printf(“%c”, var);
Writing strings:
 The writing or displaying of string may be displayed in decimal point notation using
the following width specification.
Syntax: printf(“ %s”, var);

Enhancing the readability of output:



Specify the blank spaces in between the
data items whenever necessary and applicable
  
Specify the appropriate headings and names for the variables.
  
Give the blank line as and when required.
  
Specify newline character whenever is applicable.
 
Print special text messages depending on necessity.

CONTROL STATEMENTS OR CONTROL STRUCTURES


 Programmers can take decisions in their program with help of control statements.
 Types of control statements:
1. Sequence (or) Linear Structure
2. Decision making (or) selection (or) Branching Structure
3. Looping (or) Iteration Structure
4. Unconditional Structure
S.No. Structure Name Types
1 Sequence (or) Linear Structure one by one
1. Simple if
2. If ….else
3. Nested if ….else
2 Decision making (or) Selection (or) Branching Structure
4. if……else ladder
5. Switch case
6. Nested switch case
1. while
2. do-while
3 Looping (or) Iteration Structure
3. for
4. Nested for
1. break
2. continue
4 Unconditional Structure
3. goto
4. return
1. Sequence (or) Linear Structure:
 Statements are read one by one is called sequence or linear structure.
 It is normal flow of program.
  Only one direction of every time execution.
2. Decision making (or) selection (or) Branching Structure
a) Simple if statement
  The if statement is a decision making statement.
 It is used to control the flow of execution of the statements and also used to test
 logically whether the condition is true or false.
 It is always used in conjunction with condition.
 This statement is used when a question requires answer.
Syntax Flow Chart Example

You might also like