3. Presentation By Karthik Srini
Synopsis
1. Data Types
2. Type Conversion
3. Type Definition
4. Control Structures
4. Presentation By Karthik Srini
Data Types
In the C programming language, data types refer to an extensive system
used for declaring variables or functions of different types. The type of a
variable determines how much space it occupies in storage and how the
bit pattern stored is interpreted. They are categorised as :
1. Basic Data Type
2. Enumerated Data Type
3. The void Type
4. Derived Data Type
5. Presentation By Karthik Srini
Basic Data Types
The basic data types in C are :
1. Integer data type
2. Float data type
3. Character data type
6. Presentation By Karthik Srini
Integer Data Type
The integer data types are further classified as integers and characters.
Integers can be classified with respect to length and sign as,
• Unsigned Integer
• Signed Integer
• Long Integer
• Short Integer
7. Presentation By Karthik Srini
Signed Integer & Unsigned Integer
The are normally identified by the sign in front of the integer value. An
integer value without any sign is assumed to be positive. (i.e.)
unsigned.
For example,
unsigned int num = 10 ; ( unsigned )
int num = -10 ; ( signed )
8. Presentation By Karthik Srini
Long Integer
If a large integer value is to be stored in a variable, then long is
prefixed before int while declaring the variable.
For example,
If you want to store a mobile number ( 10 digits ), you declare it as ,
long int mobile_number = 1234567891 ;
9. Presentation By Karthik Srini
Short Integer
Short integer is normally used to reduce the size of the program, since
short int occupies less memory space than int and long int .
For example,
short num = 11 ;
10. Presentation By Karthik Srini
Float Data Type
Float data type is normally used to represent floating points ( or )
floating numbers, float is prefixed before the variable name.
For example,
float pi = 3.14 ;
11. Presentation By Karthik Srini
Double Data Type
Double data type is used to represent larger floating numbers
For example,
double num = 43.66677 ;
12. Presentation By Karthik Srini
Long Double Data Type
Long double data type is used to represent even larger ( or ) longer
floating numbers.
For example,
long double num = 4167.7789056 ;
13. Presentation By Karthik Srini
Character Data Type
It is usually used to represent characters. The variable name is
prefixed by char . Must be enclosed within single quotes.
For example,
char alphabet = ‘ c ’ ;
16. Presentation By Karthik Srini
Enumerated Data Types
Enumerated data types are user defined data types. They are
predefined with a discrete set of values by the user.
For example,
enum month ( Jan , Feb , Mar , Apr , May , Jun , Jul , Aug , Sep , Oct , Nov , Dec ) ;
enum month first = Jan ;
17. Presentation By Karthik Srini
Type Definition
It is an user defined data type similar to enumerated data types, the
only difference is, in type definition it is not necessary to define the
discrete set of values.
For example,
typedef int number ;
number num1 , num2 ;
18. Presentation By Karthik Srini
The void Data Type
Void means null ( or ) nothing. It is normally prefixed before functions.
For now, this information is enough. You will learn in detail in the
forthcoming chapters.
20. Presentation By Karthik Srini
Derived Data Types
They include,
(a) Pointer types,
(b) Array types,
(c) Structure types,
(d) Union types and
(e) Function types.
21. Presentation By Karthik Srini
Arrays
Arrays are defined as the collection of variables having the same base type
( or ) data type. Arrays are further classified as :
1. Single Dimensional Array
2. Double Dimensional Array
They are normally declared as like other declarations, but the array index
must be specified.
For example,
int num [5] ;
22. Presentation By Karthik Srini
int num[5];
Memory allocation for
the above array.
0 1 2 3 4
100 34 76 56 89
24. Presentation By Karthik Srini
Type Conversion
Conversion of values of one data type into another data type is called
Type conversion. It is classified as :
1. Implicit Type Conversion
2. Explicit Type Conversion
25. Presentation By Karthik Srini
Implicit Type Conversion
These are done by the complier itself, without the knowledge of the
programmer.
For example,
int b = 7 / 2 ; ( value of b will be 4 )
26. Presentation By Karthik Srini
Explicit Type Conversion
This type of conversion are done by the user willingly.
For example,
int pi = (int) 3.4 ;
28. Presentation By Karthik Srini
Functions
A function is a group of statements that together perform a task. Every
C program has at least one function, which is main(), and all the most
trivial programs can define additional functions. You can divide up
your code into separate functions.
29. Presentation By Karthik Srini
Function Prototype
In computer programming, a function prototype or function interface is
a declaration of a function that specifies the function's name and type
signature (parameter types, and return type), but omits the function
body.
For example,
int add ( int a , int b )
31. Presentation By Karthik Srini
Control Structures
Control structure decide the way of flow of control in a program. Based
on some test conditions, the control of the program gets jumped from
one point to the other. They can be further classified as :
1. Selection Statements
2. Looping Statements
32. Presentation By Karthik Srini
Selection Statements
The control of the program gets jumped from one point to the other
based on a test expression. They are classified as :
1. If else
2. Switch Case
38. Presentation By Karthik Srini
Looping Structures
Looping is a type of control structure in which a set of instructions is
repeated again and again until the test condition evaluates to true.
There are two major types,
1. Entry controlled loop
2. Exit controlled loop
39. Presentation By Karthik Srini
Entry controlled loop
Checks whether the test expression evaluates to true, before the
statements in the loop gets executed. If the test expression evaluates
to false, the loop terminates.
These have two loops in major,
1. For loop
2. While Loop
40. Presentation By Karthik Srini
For loop
For loop has fixed number of repetitions. It is an entry controlled loop.
It consists of three main clauses namely,
1. Initialisation expression
2. Test Expression
3. Update Expression
A for loop can have multiple initialisation expressions and multiple
update expressions but can have only one test expression.
41. Presentation By Karthik Srini
for Loop Syntax
for ( initialisation exp ; test exp ; update exp )
{
action block ;
}
42. Presentation By Karthik Srini
While loop
While loop does not have fixed number of iterations. It is an entry
controlled loop.
43. Presentation By Karthik Srini
while Loop Syntax
initialisation expression ; ( if needed )
while ( condition )
{
action block ;
update expression ; ( if needed )
}
44. Presentation By Karthik Srini
Exit Controlled Loop
Checks whether the test expression evaluates to true, after the
statements in the loop gets executed. It gets executed at least once.
They have one loop in major,
1. Do While loop.
45. Presentation By Karthik Srini
Do While Loop
It is an exit controlled loop. Gets executed at least once.
46. Presentation By Karthik Srini
do while Loop Syntax
initialisation expression ;
do
{
action block ;
update expression ;
}
while ( condition ) ;