SlideShare a Scribd company logo
1 of 95
L.NIVETHA AP/CSE,KNCET
Basics of C Programming
Overview of C – C Character Set –
Identifiers and Keywords – Declaration
– Data Types – Type Qualifiers and
Type Modifiers –Variables and
Constants – Structure of a C Program –
Executing a C Program – Operators
and Expressions – Decision-Making
and Looping Statements.
L.NIVETHA AP/CSE,KNCET
 C is a general purpose, block
structured, procedural, case sensitive, free
flow, portable, and high level Programming
Language
 C having both the feature of high level
language as well as low level language
programming
 so it is called as middle level programming
language.
 C is a general purpose programming
language
 so we have to create application to all the
purposes.
Like medical, banking, library …..etc
L.NIVETHA AP/CSE,KNCET
‘C’ is most popular programming language,
It is developed by Dennis Ritchie at AT & T’s
Bell laboratory at USA in 1972.
Low level language:
 It is in terms of 0’s and 1’s ,
 ‘C’ has certain features of low “level language”,
 Using this 0’s and 1’s to create a program that is
called low level language program’s
High level language:
 It is look like a normal English.
 It is most compatible with human language.
Hear we using a to z alphabet and numbers
0-9 to make a program's called high level
language program
L.NIVETHA AP/CSE,KNCET
 ‘C’ is general purpose ,structured
programming language.
 ‘C’ is powerful and efficient and flexible.
 ‘C’ run’s into different operating system.
 ‘C’ programs are fast and efficient.
L.NIVETHA AP/CSE,KNCET
 The character set are used to represent
information.
 Also the characters used to write ‘C’
program , It is basically two types.
1. Source character set
2. Execution character set
C character
set
Alphabets
Execution
character set
Source
character set
White spaces
Special
characters
Digits
Escape
sequence
L.NIVETHA AP/CSE,KNCET
Identifiers are names given to the
different program elements,
Example: - variables , functions , arrays…etc
Rules for naming identifiers:
1. It consist of letters and digits.
2. First character must be letter, or begin with _
3. _ underscore also consider as character.
4. Both upper/lower character accepted.
5. No special character allowed.
6. identifier cannot be keyword.
L.NIVETHA AP/CSE,KNCET
 Keywords are reserved words whose meaning
has already been explained to the compiler .
 The keywords are also called reserved words.
 We won’t declare keyword as a variable or a
function name.
Example:
auto , int , long , if , static , void …. etc
L.NIVETHA AP/CSE,KNCET
The tokens are referred as individual text
and punctuation in a passage of text.
L.NIVETHA AP/CSE,KNCET
C tokens
Identifier
s
main()
Total
avg
keyword
s
int
double
for
constant
s
39
3.14
strings
“college
”
Operato
rs
+ -
Special
symbol
s
# $ %
variable is a an identifiers that is used to
store some specified type of information.
Rules for naming the variables:
1. Variable name can be character , character
with number, _ underscore with number.
2. First character must be alphabet or
underscore.
3. Variable name with in 8 character.
4. Blank space not allowed.
5. Special symbol not allowed.
L.NIVETHA AP/CSE,KNCET
Variable declaration:
syntax: data_type v1,v2,v3…….etc;
Example:
int a, b;
Initializing variables:
Syntax: data_type variable=value;
Example:
int radios=10;
float cutoff=198.4;
char c=‘a’;
L.NIVETHA AP/CSE,KNCET
 Data type is the type of data ,That are going
to access within the program.
 C support different data types.
 Each data type having predefined memory
requirement and storage representation.
 C support following four classes of data
types.
L.NIVETHA AP/CSE,KNCET
C data types
Primary User defined Derived Empty
Char
Int
Float
double
typedef
Enum
Structure
union
Arrays
Pointer
function
void
Data type Description Memory
bytes
Control
strings
Example
int integer
numbers
2 bytes %d int a=20;
float Decimal
point
numbers
4 bytes %f float b=20.1
char Single
character
1 byte %c char s= ‘ n ‘;
double Double 8 bytes %if double
L.NIVETHA AP/CSE,KNCET
Integer:
 An integer type (int ) represents signed
whole numbers . without decimal point.
They can be positive or negative numbers.
 The range is -2 , 147 to +2 , 147
1. Normal integer numbers:
It is a signed whole numbers it may be
positive or negative
Int a = 27
Int b = -23
int c = 3435
L.NIVETHA AP/CSE,KNCET
Definition:
 Floating point type represent numbers with
fractional part (or) real numbers with
decimal point.
 They can be positive or negative numbers, It
will take 4 bytes of memory.
Example:
float a = 3.14
float b = -15.45
L.NIVETHA AP/CSE,KNCET
 character is a single alphabet stored by using
single quotes.
 string are represented as near by set of
character with in double quotes.
char s=‘a’;
char name[20]=“ram”;
L.NIVETHA AP/CSE,KNCET
 double data type store both integer as well
as floating point data item.
 It will allocate 8 byte of memory space.
Example :
double s=232444;
L.NIVETHA AP/CSE,KNCET
Typedef data type:
syntax: typedef data type variablename;
Example:
typedef int mark;
mark m1,m2,m3;
Range
Signed Int -32,768 to +32, 767
Signed Char -128 to +127
Unsigned char 0 to 255
Unsigned int 0 to 65,767
L.NIVETHA AP/CSE,KNCET
Short , long , signed , unsigned.
Data type Size in bytes Control
string
Char signed and
unsigned
1 %c
Int signed 2 %d
Unsigned int 2 %u
Signed short int
Unsigned short int
1 %d
Long int 4 %id
Unsigned long int 4 %iu
float 4 %f
double 8 %if
Long double 10 %if
L.NIVETHA AP/CSE,KNCET
1. Type declaration:
syntax:
typedef data_type variable name;
Example:
typedef int mark;
mark m1,m2,m3;
2. Enumerated data type:
L.NIVETHA AP/CSE,KNCET
2. Enumerated data type:
C provides user defined data type called
enumerated data type ,it attaché names to
numbers ,here we access the enum variable by
using index position.
syntax:
enum variable {valu1, value2,
value3……etc value n };
Example:1
enum day {mon , tue , wed , ….. , sun }
printf(“mon :%d”, mon);
Output:
0
Example:2
enum day w_st, w_end;
w_st=mon , w_end=sat;
L.NIVETHA AP/CSE,KNCET
#include<stdio.h>
Void main()
{
enum colours {red=1,blue=2,green=3}
printf(“red:%d”, red);
printf(“blue:%d”,blue);
printf(“green:%d”,green);
}
Output:
red : 1
blue : 2
green: 3
L.NIVETHA AP/CSE,KNCET
The item whose value cannot change at
the time of execution are called constant.
‘C’ constants
Real constant
Integer
constant
Character
constant
Numeric
constant
String constant
Character
constant
L.NIVETHA AP/CSE,KNCET
1. Integer constant:
 It is formed with the use of sequence of digit
without decimal point , that is .
 Decimal digit - 0 to 9
 Octal digit - 0 to 7
 Hexadecimal digit - 0 to 9 A, B, C, D, E, F
Rules:
 It must be contain one digit
 Decimal point not allowed,
 It can either negative or positive,
 Range is -32,768 to +32, 767.
 No special character and blank spaces allowed with
in an integer literals
EXAMPLE:
const int mark=90 , avg=75 , total=10A1;
#define rollno 301;
L.NIVETHA AP/CSE,KNCET
2. Real constant:
It contain sequence of digits with decimal
point.
Rules:
 It must be contain one decimal digit
 It can either negative or positive,
 Range is -32,768 to +32, 767.
 No special character and blank spaces
allowed with in an float literals
Example:
const float distance =120.8;
#define pi 3.14;
L.NIVETHA AP/CSE,KNCET
Character constant:
1. Single character constant:
The character constant contain single character with in single quotes.
Syntax:
const data type variable= ‘ single character ‘;
Example:
const char initial= ‘ s ‘ ;
2. String constant:
The string constant contains more than set of character with in
double quotes.
Syntax:
const data type variable= “ string “;
Example:
const char department[5]=“IT”;
4. Declaring a variable as volatile:
Volatile data also one of constant data, it’s value modified only
with in the program, also we could not change from external.
Syntax:
volatile data type variable=constant ;
Example:
volatile const int year=2007 ;
L.NIVETHA AP/CSE,KNCET
Delimeters:
Delimeters are symbols, it not perform any
operation, only it separate the variable and
statements.
#
,
:
;
()
[]
{}
L.NIVETHA AP/CSE,KNCET
OPERATORS used in C Programs
Presented by,
L.Nivetha,AP/CSE,
KNCET
KONGUNADU COLLEGE OF ENGINEERING AND TECHNOLOGY
(AUTONOMOUS)
NAMAKKAL - TRICHY MAIN ROAD, THOTTIAM, TRICHY-621 215
L.NIVETHA AP/CSE,KNCET
1. An operator specifies the operation to be
applied to it’s operand.
2. Based on the number of operator present in
an expression, the expression are classified
as simple and compound expression.
3. An operator is symbol that specifies an
operation to be performed on the operands.
Example
A+B A,B-Operands
+Operator
L.NIVETHA AP/CSE,KNCET
1.Classification based on number of operand
2. classification based on role of an operator.
Classification based on number of operand
1. Unary arithmetic:
It require only one operand. like unary plus, unary
minus
Example: +a , -b
2. Binary arithmetic:
The binary operator operates on two operands. It
require two operand towards it’s left and right.
Example: a+b
3. Ternary Operator
A ternary operator operates on three operands.
conditional operator (?) is an ternary operator in C.
Example: big = a>b ? a : b ;
L.NIVETHA AP/CSE,KNCET
1. Arithmetic operator.
2. Relational Operator.
3. Logical Operator.
4. Assignment Operator.
5. Increment decrement operator.
6. Conditional Operator(Ternary Operator).
7. Bitwise Operator.
8. Special Operator.
L.NIVETHA AP/CSE,KNCET
 Arithmetic Operations like addition,
Subtraction, Multiplication, division ….etc.
 it can be performed by using arithmetic
operator.
The arithmetic operator available in c are.
+ - addition operator
- - subtraction operator
/ - Division operator
* - Multiplication operator
% - Modulo division operator
L.NIVETHA AP/CSE,KNCET
Example program:
#include<stdio.h>
void main()
{
int a, b, sum;
printf( “ Enter two no: “ );
scanf( “ %d %d “ , &a, &b);
sum = a + b;
printf( "Sum : %d “ , sum);
}
L.NIVETHA AP/CSE,KNCET
Relational Operator:
It is used to compare two or more
operands , operands may be variable ,
constants or expression.
< - less than
<= - less than or equal to
>= -grater than or equal to
> -grater than
= = - is equal to
! = - not equal to
L.NIVETHA AP/CSE,KNCET
#include <stdio.h>
void main()
{
int a , b ;
printf("Enter two numbers: ");
scanf( "%d %d “ , &a, &b);
if(a>b)
printf( “A is biggest number” );
else
printf( “B is biggest number” );
}
L.NIVETHA AP/CSE,KNCET
 logical operators are used to combine the
results of two or more conditions,
 And produce the result based on types of
logical operator.
&& logical AND –
 it will execute set of statement if two
condition are true,
 associativity rule is left to Right.
Syntax:
(exp1)&&(exp2)
Example:
(a>c)&&(a>b)
L.NIVETHA AP/CSE,KNCET
|| logical OR
 It will execute set of statement if any one of
the condition is true.
 Associativity rule is Left to right.
Syntax:
(exp1)||(exp2)
Example:
(a>b)||(a>d)
! Logical NOT
Here if operand is false to produce true , if
operand is true it produce false output.
associativity is Right to Left
29!=29
L.NIVETHA AP/CSE,KNCET
#include <stdio.h>
void main()
{
int a,b,c;
printf("Enter three numbers: ");
scanf( "%d %d %d", &a, &b,&c);
if(a>b)&&(a>c)
printf("A is biggest number”);
else if(b>c)
printf("B is biggest number”);
else
printf(“c is biggest number”);
}
L.NIVETHA AP/CSE,KNCET
Assignment operator used assign a values to a variable.
Syntax: variable= expression or value;
Assignment operator:
= - simple assignment
+= - assign sum
- = - assign difference
/= - assign quotient
%= - assign modulus
*= - assign product
Example:
int mark, total.
Mark=10;
Total=a+b;
Compound assignment:
x+ =y x=x+y;
Nested assignment
Y=x=20
L.NIVETHA AP/CSE,KNCET
 Here we using increment operator (+ +) it
represent adding one to the variable,
 decrement operator(- -) it represent
subtracting one to the variable ,
 These operator are called unary operator.
Because it access with single operand.
++ x - pre increment
-- X - pre decrement
X ++ - post increment
X -- -post decrement
L.NIVETHA AP/CSE,KNCET
 Conditional operator itself checks the
condition and executes the statement
depending on the condition,
 Here if the condition is true then set exp1
value otherwise set exp2 value as result
Syntax: variable = condition ? Exp1:exp2;
Example:
#include<stdio.h>
void main()
{
int a=5 , b=4 , big ;
big=a>b ? a : b;
printf( “%d” , big) ;
}
L.NIVETHA AP/CSE,KNCET
 Bitwise operator used to manipulate the data
at bit level,
 it operates on integers only.
 it not applicable to float or real.
operator meaning
& Bitwise AND
| Bitwise OR
^ Bitwise XOR
<< Shift left
>> Shift right
~ One’s complement
L.NIVETHA AP/CSE,KNCET
Bitwise AND (&)
Here operate with two operand bit by bit.
Truth table for & is:
x= 7= 0000 0111
y= 8 = 0000 1000
OUTPUT: 0000 0000
Bitwise OR ( |)
x= 7= 0000 0111
y= 8 = 0000 1000
8421
OUTPUT:0000 1111
Bitwise exclusive OR (^)
x= 7= 0000 0111
y= 8 = 0000 1000
OUTPUT: 0000 1111
& 0 1
0 0 0
1 0 1
| 0 1
0 0 1
1 1 1
^ 0 1
0 0 1
1 1 0
L.NIVETHA AP/CSE,KNCET
Operators Meaning
, Comma operator used for
separation of variable
sizeof Size of operator used for find
the total bytes of a variable
Syntax: sizeof(var)
& and * & Symbol represent address
of the variable
* Symbol represent value of
the variable
. And --> It represent access element
from the structure.
L.NIVETHA AP/CSE,KNCET
 Arithmetic expression are evaluated by
using it’s precedence(PEMDAS).
 When an expression contains more than
one operator , then the order of evaluation
depends on it’s operator precedence.
 Parentheses having highest precedence , it
is executed first with in the expression.
Example:
5*(5+3) = 40
In this expression first execute
parenthesis , then multiply with five and
produce 40 as result.
L.NIVETHA AP/CSE,KNCET
 Next highest precedence is exponentiation
 Next highest precedence is multiplication
and division ( * , / , % )
 The lowest precedence is addition and
subtraction.( + , -)
 Operator with the same precedence are
evaluated from left to right.
EXAMPLE:
Workout this expression and write correct
answer .
3 – 9*(3 + 7)+7 * 3 – 1
L.NIVETHA AP/CSE,KNCET
 It is defined as interconnection of operands
and operator.
 Based on the operator present in the
expression that is classified as
1. Simple expression
2. Compound expression.
Here we convert the various equation of
math's and physics equation into expression
Syntax: variable=expression;
Example : int a=2,b=3,c=4;
Sum=a+b*c; 20
12+2=14
L.NIVETHA AP/CSE,KNCET
 Branching statement are used to transfer
the program control from one point to
another point.
They are classified as
1. Conditional statement – selection statement.
 Conditional branching also known as
selection statement.
 In this the program control transferred
from one point to another point based on
the condition.
L.NIVETHA AP/CSE,KNCET
2. Unconditional statement – jumping
statement.
 Unconditional statement also known as
jumping statement
 Here program control transferred from one
point to another point without checking any
condition.
L.NIVETHA AP/CSE,KNCET
‘c’ control statements
i. Sequential structure:
instruction are executed in sequence
i=i+1;
j=j+1;
ii. Selection structure:
if(x>y)
i=i+1;
else
J=j+1;
L.NIVETHA AP/CSE,KNCET
iii. Iteration structure (or) loop:
for(i=0;i<=5;i++)
{
Printf(“hello”);
}
iv. Encapsulation structure.
for(i=0;i<=5;i++)
if(condition)
{
Printf(“hello”);
}
else
{
Printf(“hai”);
}
L.NIVETHA AP/CSE,KNCET
1. If statement
2. If-else statement
3. Nested if- else statement
4. If-else ladder statement
5. Switch case statement
L.NIVETHA AP/CSE,KNCET
 if is a decision making statement.
 It is used to control the flow of execution,
 so to test logically whether the condition is
true or false.
Syntax:
if(condition)
true false
{
true statements;
}
condition
True statement
L.NIVETHA AP/CSE,KNCET
#include <stdio.h>
void main()
{
int a,b;
printf("Enter two numbers: ");
scanf("%d %d ", &a, &b);
if(a>b)
{
printf("A is biggest number”);
}
}
L.NIVETHA AP/CSE,KNCET
 It is basically two way decision making statement,
 Here it check the condition if the condition is true
means it execute the true statements,
 If it is false execute another set of statement.
Syantax:
if(condition)
true
false
{
true statement;
}
else
{
false statement;
}
conditio
n
True
statement
False
statement
L.NIVETHA AP/CSE,KNCET
#include <stdio.h>
void main()
{
int a,b;
printf("Enter two numbers: ");
scanf("%d %d ", &a, &b);
if(a>b)
printf("A is biggest number”);
else
printf("B is biggest number”);
}
L.NIVETHA AP/CSE,KNCET
It is defined as we can write a entire
if…else statement in another if…else
statement called nesting.
true
false
true false
Conditio
n 1
Conditi
on 2
true
statement 2
True
statement 1
False
statement 2
L.NIVETHA AP/CSE,KNCET
If(condition 1)
{
true statement – 1
}
else if (condition – 2 )
{
true statement – 2
}
else
{
false statement – 2
}
L.NIVETHA AP/CSE,KNCET
#include<stdio.h>
Void main()
{
int a,b,c;
printf(“enter three values:”);
scanf(“%d%d%d”,&a,&b,&c);
if(a>b)&&(a>c)
{
printf(“a is biggest number”);
}
else if(b>c)
{
printf(“b is biggest number”);
}
else
{
printf(“c is biggest number”);
} L.NIVETHA AP/CSE,KNCET
 The if…else statement contain more than
two are three if…else statement with in this
called nested if….else statement.
 (Or) it is called as if …else ladder.
true false
true false
true
false
conditi
on1
Condition
3
conditi
on2
True statement
1
True
statement 2
True
statement 3
False
statement 3
L.NIVETHA AP/CSE,KNCET
Write a c program to check whether the given number is +ve or _ve Or zero.
#include<stdio.h>
#include<conio.h>
Void main()
{
int num;
printf(“Enter the number”);
scanf(“%d”, &num);
clrscr();
if(num==0)
printf(“The number is zero”);
else if(num>0)
printf(“+ve number ”);
else if(num<0)
printf(“-ve number ”);
else
printf(“Enter valid number ”);
return(o);
getch();
}
L.NIVETHA AP/CSE,KNCET
It is a multi way decision statement ,
Using the value of a given variable and it
check with case values,
if it found execute those block of values ,
if not found it execute default statement.
L.NIVETHA AP/CSE,KNCET
Syntax:
switch(expression)
{
case constant1:
block1;
break;
case constant2:
block2;
break;
.
.
.
default:
default block;
break;
}
L.NIVETHA AP/CSE,KNCET
SIMULATING SIMPLE
CALCULATOR:
#include<stdio.h>
#include<conio.h>
Void main()
{
Int n1,n2;
Char op;
Printf (“enter the
expression”);
Scanf(“ %d%c%d ”,
&n1,&op,&n2);
Switch(op)
{
case ‘ + ’ :
printf( “%d” ,n1+n2);
break;
Case ‘ - ’ :
printf( “%d” ,n1-n2);
break;
Case ‘ * ’ :
printf( “%d” ,n1*n2);
break;
Case ‘ / ’:
printf( “%d” ,n1/n2);
break;
default:
printf(“invalid
operator”)
}
}
L.NIVETHA AP/CSE,KNCET
The jump statement transfer the control
from one point to another point without
checking any condition. The following jump
statement used in C language.
1. goto statement
2. break statement
3. Continue statement
4. return statement
L.NIVETHA AP/CSE,KNCET
goto statement:
 The goto statement are used to transfer the
control unconditionally from one point to
another point with in the function.
 It provide a highly unstructured way of
transferring the program control from one
point to another point.
 It often makes the program control difficult
to understand and modify.
Syntax:
goto label;
L.NIVETHA AP/CSE,KNCET
 The goto statement is always used in joining
with an identifier-labeled statement.
 The goto statement at the time of execution
transfers the program control to an
identifier-labeled statement, The label name
used in the goto statement .
 The goto statement can be used to make a
forward jump as well as backward jump.
 The goto statement transfer control any
where with in the function, but it no way to
take the control out of the function.
L.NIVETHA AP/CSE,KNCET
Forward jump:
goto label;
……………..
……………..
label;
Statement
backward jump:
Label;
statement;
………….
………….
goto label;
L.NIVETHA AP/CSE,KNCET
 Break is a loop control statement .
 The break statement is used to terminate the
loop
 when the break statement enter inside a loop
,then the loop is exit immediately
 The break statement can be used in both
while and for loop.
L.NIVETHA AP/CSE,KNCET
L.NIVETHA AP/CSE,KNCET
Example:
#include<stdio.h>
Void main()
{
int i;
for(i=0; i<=5;i++)
{
if(i==3)
{
break;
}
printf(“Hai”);
}
} L.NIVETHA AP/CSE,KNCET
 The continue statement rejects all the
remaining statements in the current iteration
of the for loop
 and moves the control back to the top of the
loop.
 When the statement continue is entered into
any C loop control automatically passes to
the beginning of the loop
L.NIVETHA AP/CSE,KNCET
L.NIVETHA AP/CSE,KNCET
for(i=0; i<=5;i++)
{
if(i==3)
{
continue;
}
printf(“Hai”);
}
}
L.NIVETHA AP/CSE,KNCET
 The return statement terminate the execution
of a function
 It returns the control to the calling function.
 A return statement without an expression can
appear only in a function whose return type is
void.
 Example :
return();
Or return(expression);
L.NIVETHA AP/CSE,KNCET
The loop is defined as the block of
statements which are repeatedly executed for
a certain number of time.
1. while statement(entry check loop)(top tested
loop).
2. Do while statement(bottom tested loop)(exit
check loop).
3. for statement.
L.NIVETHA AP/CSE,KNCET
The while loop is an entry controlled loop
statement ,It means the condition is
evaluated first , if it is true repeatedly execute
the body of the loop until the condition
become false.
Syntax: false
while(condition)
{ true
…….
body of the loop;
…….
}
conditio
n
Body of the loop
L.NIVETHA AP/CSE,KNCET
#include<stdio.h>
Void main()
{
Int n,I,sum=0;
n =5;
i=1;
While(n>=i)
sum=sum+i;
i=i+1;
Printf(“%d”, sum);
}
L.NIVETHA AP/CSE,KNCET
The do…while statement is exit control
statement , Here the body of the statement
executed one’s after that check the condition.
Syntax:
do
{
……
body of the loop; true
……
}
while (condition)
false
Body of the loop
conditio
n
L.NIVETHA AP/CSE,KNCET
Example program:
#include<stdio.h>
void main()
{
int i=1, sum=0, n;
n=5
do
{
sum=sum+i;
i=i+1;
}
while(n>=i)
printf(“the sum of 5 is:%d”, sum);
}
L.NIVETHA AP/CSE,KNCET
This is another one of looping structure, it
is execute set of instructions repeatedly until
the condition become false.
Syntax:
for(initialization sec ;condition checking ;
increment / decrement)
{
……
body of the loop;
……
true
}
Initialization
Increment /
decrement
Body of the
loop
conditio
n
L.NIVETHA AP/CSE,KNCET
#include<stdio.h>
Void main()
{
int n, i, sum=0;
printf("Enter n value ");
scanf("%d" , &n);
for(i=1;n>=i ; i++)
{
sum=sum +i;
}
printf("%d", sum);
}
L.NIVETHA AP/CSE,KNCET
A constant is an entity whose value
remains the same throughout the execution
of a program.
Constant are classified as:
1. Literal constant
2. Qualified constant
3. Symbolic Constant
L.NIVETHA AP/CSE,KNCET
literal
constants
Floating point
literal constant
Integer literal
constant
Character
literal constant
Numeric literal
constant
String literal
constant
Character
literal constant
L.NIVETHA AP/CSE,KNCET
1. Integer literal constant:
 It is formed with the use of sequence of digit without
decimal point , that is .
 Decimal digit - 0 to 9
 Octal digit - 0 to 7
 Hexadecimal digit - 0 to 9 A, B, C, D, E, F
Rules:
 It must be contain one digit
 Decimal point not allowed,
 It can either negative or positive,
 Range is -32,768 to +32, 767.
 No special character and blank spaces allowed with in an
integer literals
EXAMPLE:
int mark=90 , avg=75 , total=10A1;
L.NIVETHA AP/CSE,KNCET
2. Real constant:
It contain sequence of digits with decimal
point.
Rules:
 It must be contain one decimal digit
 It can either negative or positive,
 Range is -32,768 to +32, 767.
 No special character and blank spaces
allowed with in an float literals
Example:
float distance =120.8;
L.NIVETHA AP/CSE,KNCET
Character literal constant:
1. Single character literal constant:
The character constant contain single character with in
single quotes.
Syntax:
data type variable= ‘ single character ‘;
Example:
char initial= ‘ s ‘ ;
2. String literal constant:
The string constant contains more than set of
character with in double quotes.
Syntax:
data type variable= “ string “;
Example:
char department[5]=“IT”;
L.NIVETHA AP/CSE,KNCET
Qualified constant are created by using
const keyword .
Example:
const char a=‘s’;
const int a=10;
if we declare normal variable and assign
10, like int a = 10; then this variable
allocate 2byte memory space and store 10
with In those space.
consider the statement const int a =10;
the usage of qualified constant is after
storing value 10 those memory block is
locked, also could not allow new value with in
this.
L.NIVETHA AP/CSE,KNCET
Symbolic constant are created with the
help of the #define preprocessor.
Example :
#define pi 3.14
Here pi is a symbolic constant or
called as macro constant.
L.NIVETHA AP/CSE,KNCET
A type qualifier cannot affect the range of
the values, but affect the arithmetic
properties of the declared object.
There are two types:
1. Const - declaring an object by using const
then that value cannot be modified during
the execution.
2. Volatile – this object has some special
properties.
L.NIVETHA AP/CSE,KNCET
Declaring a variable as volatile:
Volatile data also one of constant data, it’s
value modified only with in the program, also
we could not change from external.
Syntax:
volatile data type
variable=constant ;
Example:
volatile int year=2007 ;
L.NIVETHA AP/CSE,KNCET
A type modifier modifies the range of the
object.
There are following types:
1. Signed ( negative number )
2. Unsigned ( zero or positive number )
3. Short
4. Long
L.NIVETHA AP/CSE,KNCET
Short , long , signed , unsigned.
Data type Size in bytes Control
string
Char signed and
unsigned
1 %c
Int signed 2 %d
Unsigned int 2 %u
Signed short int
Unsigned short int
1 %d
Long int 4 %id
Unsigned long int 4 %iu
float 4 %f
double 8 %if
Long double 10 %if
L.NIVETHA AP/CSE,KNCET
#include<stdio.h>
#include<conio.h>
#include<math.h>
Void main()
{
int a, b ,c,first;
printf(“Enter three numbers a,b,c”);
scanf( “ %d%d%d”, &a,&b,&c);
First=-b+sqrt((b*b-4*a*c)/(2*a));
printf(“%d”, first);
}
L.NIVETHA AP/CSE,KNCET
#include<stdio.h>
#include<conio.h>
Int main()
{
int num;
printf(“Enter a number ”)’
scanf(“%d”, &num);
if((num%2)==0)
printf(“Given number is even”);
else
Printf(“Given number is odd”);
return(0);
}
L.NIVETHA AP/CSE,KNCET

More Related Content

Similar to U2.ppt

Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C ProgrammingMOHAMAD NOH AHMAD
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 FocJAYA
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C ProgrammingAniket Patne
 
C programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer CentreC programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer Centrejatin batra
 
C programming notes.pdf
C programming notes.pdfC programming notes.pdf
C programming notes.pdfAdiseshaK
 
unit 1 cpds.pptx
unit 1 cpds.pptxunit 1 cpds.pptx
unit 1 cpds.pptxmadhurij54
 
Mca i pic u-2 datatypes and variables in c language
Mca i pic u-2 datatypes and variables in c languageMca i pic u-2 datatypes and variables in c language
Mca i pic u-2 datatypes and variables in c languageRai University
 
Btech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c languageBtech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c languageRai University
 
datatypes and variables in c language
 datatypes and variables in c language datatypes and variables in c language
datatypes and variables in c languageRai University
 
Basic of the C language
Basic of the C languageBasic of the C language
Basic of the C languageSachin Verma
 
Diploma ii cfpc u-2 datatypes and variables in c language
Diploma ii  cfpc u-2 datatypes and variables in c languageDiploma ii  cfpc u-2 datatypes and variables in c language
Diploma ii cfpc u-2 datatypes and variables in c languageRai University
 
Bsc cs i pic u-2 datatypes and variables in c language
Bsc cs i pic u-2 datatypes and variables in c languageBsc cs i pic u-2 datatypes and variables in c language
Bsc cs i pic u-2 datatypes and variables in c languageRai University
 

Similar to U2.ppt (20)

PSPC--UNIT-2.pdf
PSPC--UNIT-2.pdfPSPC--UNIT-2.pdf
PSPC--UNIT-2.pdf
 
C material
C materialC material
C material
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Basics of c
Basics of cBasics of c
Basics of c
 
C introduction
C introductionC introduction
C introduction
 
Cnotes
CnotesCnotes
Cnotes
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
C programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer CentreC programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer Centre
 
C programming notes.pdf
C programming notes.pdfC programming notes.pdf
C programming notes.pdf
 
unit 1 cpds.pptx
unit 1 cpds.pptxunit 1 cpds.pptx
unit 1 cpds.pptx
 
Mca i pic u-2 datatypes and variables in c language
Mca i pic u-2 datatypes and variables in c languageMca i pic u-2 datatypes and variables in c language
Mca i pic u-2 datatypes and variables in c language
 
Btech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c languageBtech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c language
 
datatypes and variables in c language
 datatypes and variables in c language datatypes and variables in c language
datatypes and variables in c language
 
C programming notes
C programming notesC programming notes
C programming notes
 
Basic of the C language
Basic of the C languageBasic of the C language
Basic of the C language
 
history of c.ppt
history of c.ppthistory of c.ppt
history of c.ppt
 
Diploma ii cfpc u-2 datatypes and variables in c language
Diploma ii  cfpc u-2 datatypes and variables in c languageDiploma ii  cfpc u-2 datatypes and variables in c language
Diploma ii cfpc u-2 datatypes and variables in c language
 
Bsc cs i pic u-2 datatypes and variables in c language
Bsc cs i pic u-2 datatypes and variables in c languageBsc cs i pic u-2 datatypes and variables in c language
Bsc cs i pic u-2 datatypes and variables in c language
 

More from Kongunadu College of Engineering and Technology (19)

Unit V - ppt.pptx
Unit V - ppt.pptxUnit V - ppt.pptx
Unit V - ppt.pptx
 
C++ UNIT4.pptx
C++ UNIT4.pptxC++ UNIT4.pptx
C++ UNIT4.pptx
 
c++ Unit I.pptx
c++ Unit I.pptxc++ Unit I.pptx
c++ Unit I.pptx
 
c++ Unit III - PPT.pptx
c++ Unit III - PPT.pptxc++ Unit III - PPT.pptx
c++ Unit III - PPT.pptx
 
c++ UNIT II.pptx
c++ UNIT II.pptxc++ UNIT II.pptx
c++ UNIT II.pptx
 
UNIT 1.pptx
UNIT 1.pptxUNIT 1.pptx
UNIT 1.pptx
 
UNIT 4.pptx
UNIT 4.pptxUNIT 4.pptx
UNIT 4.pptx
 
UNIT 5.pptx
UNIT 5.pptxUNIT 5.pptx
UNIT 5.pptx
 
UNIT 2.pptx
UNIT 2.pptxUNIT 2.pptx
UNIT 2.pptx
 
UNIT 3.pptx
UNIT 3.pptxUNIT 3.pptx
UNIT 3.pptx
 
Unit - 1.ppt
Unit - 1.pptUnit - 1.ppt
Unit - 1.ppt
 
UNIT 5.pptx
UNIT 5.pptxUNIT 5.pptx
UNIT 5.pptx
 
Unit - 2.ppt
Unit - 2.pptUnit - 2.ppt
Unit - 2.ppt
 
Unit - 3.pptx
Unit - 3.pptxUnit - 3.pptx
Unit - 3.pptx
 
Unit - 4.ppt
Unit - 4.pptUnit - 4.ppt
Unit - 4.ppt
 
U1.ppt
U1.pptU1.ppt
U1.ppt
 
U4.ppt
U4.pptU4.ppt
U4.ppt
 
U5 SPC.pptx
U5 SPC.pptxU5 SPC.pptx
U5 SPC.pptx
 
U3.pptx
U3.pptxU3.pptx
U3.pptx
 

Recently uploaded

What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 

Recently uploaded (20)

What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 

U2.ppt

  • 2. Basics of C Programming Overview of C – C Character Set – Identifiers and Keywords – Declaration – Data Types – Type Qualifiers and Type Modifiers –Variables and Constants – Structure of a C Program – Executing a C Program – Operators and Expressions – Decision-Making and Looping Statements. L.NIVETHA AP/CSE,KNCET
  • 3.  C is a general purpose, block structured, procedural, case sensitive, free flow, portable, and high level Programming Language  C having both the feature of high level language as well as low level language programming  so it is called as middle level programming language.  C is a general purpose programming language  so we have to create application to all the purposes. Like medical, banking, library …..etc L.NIVETHA AP/CSE,KNCET
  • 4. ‘C’ is most popular programming language, It is developed by Dennis Ritchie at AT & T’s Bell laboratory at USA in 1972. Low level language:  It is in terms of 0’s and 1’s ,  ‘C’ has certain features of low “level language”,  Using this 0’s and 1’s to create a program that is called low level language program’s High level language:  It is look like a normal English.  It is most compatible with human language. Hear we using a to z alphabet and numbers 0-9 to make a program's called high level language program L.NIVETHA AP/CSE,KNCET
  • 5.  ‘C’ is general purpose ,structured programming language.  ‘C’ is powerful and efficient and flexible.  ‘C’ run’s into different operating system.  ‘C’ programs are fast and efficient. L.NIVETHA AP/CSE,KNCET
  • 6.  The character set are used to represent information.  Also the characters used to write ‘C’ program , It is basically two types. 1. Source character set 2. Execution character set C character set Alphabets Execution character set Source character set White spaces Special characters Digits Escape sequence L.NIVETHA AP/CSE,KNCET
  • 7. Identifiers are names given to the different program elements, Example: - variables , functions , arrays…etc Rules for naming identifiers: 1. It consist of letters and digits. 2. First character must be letter, or begin with _ 3. _ underscore also consider as character. 4. Both upper/lower character accepted. 5. No special character allowed. 6. identifier cannot be keyword. L.NIVETHA AP/CSE,KNCET
  • 8.  Keywords are reserved words whose meaning has already been explained to the compiler .  The keywords are also called reserved words.  We won’t declare keyword as a variable or a function name. Example: auto , int , long , if , static , void …. etc L.NIVETHA AP/CSE,KNCET
  • 9. The tokens are referred as individual text and punctuation in a passage of text. L.NIVETHA AP/CSE,KNCET C tokens Identifier s main() Total avg keyword s int double for constant s 39 3.14 strings “college ” Operato rs + - Special symbol s # $ %
  • 10. variable is a an identifiers that is used to store some specified type of information. Rules for naming the variables: 1. Variable name can be character , character with number, _ underscore with number. 2. First character must be alphabet or underscore. 3. Variable name with in 8 character. 4. Blank space not allowed. 5. Special symbol not allowed. L.NIVETHA AP/CSE,KNCET
  • 11. Variable declaration: syntax: data_type v1,v2,v3…….etc; Example: int a, b; Initializing variables: Syntax: data_type variable=value; Example: int radios=10; float cutoff=198.4; char c=‘a’; L.NIVETHA AP/CSE,KNCET
  • 12.  Data type is the type of data ,That are going to access within the program.  C support different data types.  Each data type having predefined memory requirement and storage representation.  C support following four classes of data types. L.NIVETHA AP/CSE,KNCET
  • 13. C data types Primary User defined Derived Empty Char Int Float double typedef Enum Structure union Arrays Pointer function void Data type Description Memory bytes Control strings Example int integer numbers 2 bytes %d int a=20; float Decimal point numbers 4 bytes %f float b=20.1 char Single character 1 byte %c char s= ‘ n ‘; double Double 8 bytes %if double L.NIVETHA AP/CSE,KNCET
  • 14. Integer:  An integer type (int ) represents signed whole numbers . without decimal point. They can be positive or negative numbers.  The range is -2 , 147 to +2 , 147 1. Normal integer numbers: It is a signed whole numbers it may be positive or negative Int a = 27 Int b = -23 int c = 3435 L.NIVETHA AP/CSE,KNCET
  • 15. Definition:  Floating point type represent numbers with fractional part (or) real numbers with decimal point.  They can be positive or negative numbers, It will take 4 bytes of memory. Example: float a = 3.14 float b = -15.45 L.NIVETHA AP/CSE,KNCET
  • 16.  character is a single alphabet stored by using single quotes.  string are represented as near by set of character with in double quotes. char s=‘a’; char name[20]=“ram”; L.NIVETHA AP/CSE,KNCET
  • 17.  double data type store both integer as well as floating point data item.  It will allocate 8 byte of memory space. Example : double s=232444; L.NIVETHA AP/CSE,KNCET
  • 18. Typedef data type: syntax: typedef data type variablename; Example: typedef int mark; mark m1,m2,m3; Range Signed Int -32,768 to +32, 767 Signed Char -128 to +127 Unsigned char 0 to 255 Unsigned int 0 to 65,767 L.NIVETHA AP/CSE,KNCET
  • 19. Short , long , signed , unsigned. Data type Size in bytes Control string Char signed and unsigned 1 %c Int signed 2 %d Unsigned int 2 %u Signed short int Unsigned short int 1 %d Long int 4 %id Unsigned long int 4 %iu float 4 %f double 8 %if Long double 10 %if L.NIVETHA AP/CSE,KNCET
  • 20. 1. Type declaration: syntax: typedef data_type variable name; Example: typedef int mark; mark m1,m2,m3; 2. Enumerated data type: L.NIVETHA AP/CSE,KNCET
  • 21. 2. Enumerated data type: C provides user defined data type called enumerated data type ,it attaché names to numbers ,here we access the enum variable by using index position. syntax: enum variable {valu1, value2, value3……etc value n }; Example:1 enum day {mon , tue , wed , ….. , sun } printf(“mon :%d”, mon); Output: 0 Example:2 enum day w_st, w_end; w_st=mon , w_end=sat; L.NIVETHA AP/CSE,KNCET
  • 22. #include<stdio.h> Void main() { enum colours {red=1,blue=2,green=3} printf(“red:%d”, red); printf(“blue:%d”,blue); printf(“green:%d”,green); } Output: red : 1 blue : 2 green: 3 L.NIVETHA AP/CSE,KNCET
  • 23. The item whose value cannot change at the time of execution are called constant. ‘C’ constants Real constant Integer constant Character constant Numeric constant String constant Character constant L.NIVETHA AP/CSE,KNCET
  • 24. 1. Integer constant:  It is formed with the use of sequence of digit without decimal point , that is .  Decimal digit - 0 to 9  Octal digit - 0 to 7  Hexadecimal digit - 0 to 9 A, B, C, D, E, F Rules:  It must be contain one digit  Decimal point not allowed,  It can either negative or positive,  Range is -32,768 to +32, 767.  No special character and blank spaces allowed with in an integer literals EXAMPLE: const int mark=90 , avg=75 , total=10A1; #define rollno 301; L.NIVETHA AP/CSE,KNCET
  • 25. 2. Real constant: It contain sequence of digits with decimal point. Rules:  It must be contain one decimal digit  It can either negative or positive,  Range is -32,768 to +32, 767.  No special character and blank spaces allowed with in an float literals Example: const float distance =120.8; #define pi 3.14; L.NIVETHA AP/CSE,KNCET
  • 26. Character constant: 1. Single character constant: The character constant contain single character with in single quotes. Syntax: const data type variable= ‘ single character ‘; Example: const char initial= ‘ s ‘ ; 2. String constant: The string constant contains more than set of character with in double quotes. Syntax: const data type variable= “ string “; Example: const char department[5]=“IT”; 4. Declaring a variable as volatile: Volatile data also one of constant data, it’s value modified only with in the program, also we could not change from external. Syntax: volatile data type variable=constant ; Example: volatile const int year=2007 ; L.NIVETHA AP/CSE,KNCET
  • 27. Delimeters: Delimeters are symbols, it not perform any operation, only it separate the variable and statements. # , : ; () [] {} L.NIVETHA AP/CSE,KNCET
  • 28. OPERATORS used in C Programs Presented by, L.Nivetha,AP/CSE, KNCET KONGUNADU COLLEGE OF ENGINEERING AND TECHNOLOGY (AUTONOMOUS) NAMAKKAL - TRICHY MAIN ROAD, THOTTIAM, TRICHY-621 215 L.NIVETHA AP/CSE,KNCET
  • 29. 1. An operator specifies the operation to be applied to it’s operand. 2. Based on the number of operator present in an expression, the expression are classified as simple and compound expression. 3. An operator is symbol that specifies an operation to be performed on the operands. Example A+B A,B-Operands +Operator L.NIVETHA AP/CSE,KNCET
  • 30. 1.Classification based on number of operand 2. classification based on role of an operator. Classification based on number of operand 1. Unary arithmetic: It require only one operand. like unary plus, unary minus Example: +a , -b 2. Binary arithmetic: The binary operator operates on two operands. It require two operand towards it’s left and right. Example: a+b 3. Ternary Operator A ternary operator operates on three operands. conditional operator (?) is an ternary operator in C. Example: big = a>b ? a : b ; L.NIVETHA AP/CSE,KNCET
  • 31. 1. Arithmetic operator. 2. Relational Operator. 3. Logical Operator. 4. Assignment Operator. 5. Increment decrement operator. 6. Conditional Operator(Ternary Operator). 7. Bitwise Operator. 8. Special Operator. L.NIVETHA AP/CSE,KNCET
  • 32.  Arithmetic Operations like addition, Subtraction, Multiplication, division ….etc.  it can be performed by using arithmetic operator. The arithmetic operator available in c are. + - addition operator - - subtraction operator / - Division operator * - Multiplication operator % - Modulo division operator L.NIVETHA AP/CSE,KNCET
  • 33. Example program: #include<stdio.h> void main() { int a, b, sum; printf( “ Enter two no: “ ); scanf( “ %d %d “ , &a, &b); sum = a + b; printf( "Sum : %d “ , sum); } L.NIVETHA AP/CSE,KNCET
  • 34. Relational Operator: It is used to compare two or more operands , operands may be variable , constants or expression. < - less than <= - less than or equal to >= -grater than or equal to > -grater than = = - is equal to ! = - not equal to L.NIVETHA AP/CSE,KNCET
  • 35. #include <stdio.h> void main() { int a , b ; printf("Enter two numbers: "); scanf( "%d %d “ , &a, &b); if(a>b) printf( “A is biggest number” ); else printf( “B is biggest number” ); } L.NIVETHA AP/CSE,KNCET
  • 36.  logical operators are used to combine the results of two or more conditions,  And produce the result based on types of logical operator. && logical AND –  it will execute set of statement if two condition are true,  associativity rule is left to Right. Syntax: (exp1)&&(exp2) Example: (a>c)&&(a>b) L.NIVETHA AP/CSE,KNCET
  • 37. || logical OR  It will execute set of statement if any one of the condition is true.  Associativity rule is Left to right. Syntax: (exp1)||(exp2) Example: (a>b)||(a>d) ! Logical NOT Here if operand is false to produce true , if operand is true it produce false output. associativity is Right to Left 29!=29 L.NIVETHA AP/CSE,KNCET
  • 38. #include <stdio.h> void main() { int a,b,c; printf("Enter three numbers: "); scanf( "%d %d %d", &a, &b,&c); if(a>b)&&(a>c) printf("A is biggest number”); else if(b>c) printf("B is biggest number”); else printf(“c is biggest number”); } L.NIVETHA AP/CSE,KNCET
  • 39. Assignment operator used assign a values to a variable. Syntax: variable= expression or value; Assignment operator: = - simple assignment += - assign sum - = - assign difference /= - assign quotient %= - assign modulus *= - assign product Example: int mark, total. Mark=10; Total=a+b; Compound assignment: x+ =y x=x+y; Nested assignment Y=x=20 L.NIVETHA AP/CSE,KNCET
  • 40.  Here we using increment operator (+ +) it represent adding one to the variable,  decrement operator(- -) it represent subtracting one to the variable ,  These operator are called unary operator. Because it access with single operand. ++ x - pre increment -- X - pre decrement X ++ - post increment X -- -post decrement L.NIVETHA AP/CSE,KNCET
  • 41.  Conditional operator itself checks the condition and executes the statement depending on the condition,  Here if the condition is true then set exp1 value otherwise set exp2 value as result Syntax: variable = condition ? Exp1:exp2; Example: #include<stdio.h> void main() { int a=5 , b=4 , big ; big=a>b ? a : b; printf( “%d” , big) ; } L.NIVETHA AP/CSE,KNCET
  • 42.  Bitwise operator used to manipulate the data at bit level,  it operates on integers only.  it not applicable to float or real. operator meaning & Bitwise AND | Bitwise OR ^ Bitwise XOR << Shift left >> Shift right ~ One’s complement L.NIVETHA AP/CSE,KNCET
  • 43. Bitwise AND (&) Here operate with two operand bit by bit. Truth table for & is: x= 7= 0000 0111 y= 8 = 0000 1000 OUTPUT: 0000 0000 Bitwise OR ( |) x= 7= 0000 0111 y= 8 = 0000 1000 8421 OUTPUT:0000 1111 Bitwise exclusive OR (^) x= 7= 0000 0111 y= 8 = 0000 1000 OUTPUT: 0000 1111 & 0 1 0 0 0 1 0 1 | 0 1 0 0 1 1 1 1 ^ 0 1 0 0 1 1 1 0 L.NIVETHA AP/CSE,KNCET
  • 44. Operators Meaning , Comma operator used for separation of variable sizeof Size of operator used for find the total bytes of a variable Syntax: sizeof(var) & and * & Symbol represent address of the variable * Symbol represent value of the variable . And --> It represent access element from the structure. L.NIVETHA AP/CSE,KNCET
  • 45.  Arithmetic expression are evaluated by using it’s precedence(PEMDAS).  When an expression contains more than one operator , then the order of evaluation depends on it’s operator precedence.  Parentheses having highest precedence , it is executed first with in the expression. Example: 5*(5+3) = 40 In this expression first execute parenthesis , then multiply with five and produce 40 as result. L.NIVETHA AP/CSE,KNCET
  • 46.  Next highest precedence is exponentiation  Next highest precedence is multiplication and division ( * , / , % )  The lowest precedence is addition and subtraction.( + , -)  Operator with the same precedence are evaluated from left to right. EXAMPLE: Workout this expression and write correct answer . 3 – 9*(3 + 7)+7 * 3 – 1 L.NIVETHA AP/CSE,KNCET
  • 47.  It is defined as interconnection of operands and operator.  Based on the operator present in the expression that is classified as 1. Simple expression 2. Compound expression. Here we convert the various equation of math's and physics equation into expression Syntax: variable=expression; Example : int a=2,b=3,c=4; Sum=a+b*c; 20 12+2=14 L.NIVETHA AP/CSE,KNCET
  • 48.  Branching statement are used to transfer the program control from one point to another point. They are classified as 1. Conditional statement – selection statement.  Conditional branching also known as selection statement.  In this the program control transferred from one point to another point based on the condition. L.NIVETHA AP/CSE,KNCET
  • 49. 2. Unconditional statement – jumping statement.  Unconditional statement also known as jumping statement  Here program control transferred from one point to another point without checking any condition. L.NIVETHA AP/CSE,KNCET
  • 50. ‘c’ control statements i. Sequential structure: instruction are executed in sequence i=i+1; j=j+1; ii. Selection structure: if(x>y) i=i+1; else J=j+1; L.NIVETHA AP/CSE,KNCET
  • 51. iii. Iteration structure (or) loop: for(i=0;i<=5;i++) { Printf(“hello”); } iv. Encapsulation structure. for(i=0;i<=5;i++) if(condition) { Printf(“hello”); } else { Printf(“hai”); } L.NIVETHA AP/CSE,KNCET
  • 52. 1. If statement 2. If-else statement 3. Nested if- else statement 4. If-else ladder statement 5. Switch case statement L.NIVETHA AP/CSE,KNCET
  • 53.  if is a decision making statement.  It is used to control the flow of execution,  so to test logically whether the condition is true or false. Syntax: if(condition) true false { true statements; } condition True statement L.NIVETHA AP/CSE,KNCET
  • 54. #include <stdio.h> void main() { int a,b; printf("Enter two numbers: "); scanf("%d %d ", &a, &b); if(a>b) { printf("A is biggest number”); } } L.NIVETHA AP/CSE,KNCET
  • 55.  It is basically two way decision making statement,  Here it check the condition if the condition is true means it execute the true statements,  If it is false execute another set of statement. Syantax: if(condition) true false { true statement; } else { false statement; } conditio n True statement False statement L.NIVETHA AP/CSE,KNCET
  • 56. #include <stdio.h> void main() { int a,b; printf("Enter two numbers: "); scanf("%d %d ", &a, &b); if(a>b) printf("A is biggest number”); else printf("B is biggest number”); } L.NIVETHA AP/CSE,KNCET
  • 57. It is defined as we can write a entire if…else statement in another if…else statement called nesting. true false true false Conditio n 1 Conditi on 2 true statement 2 True statement 1 False statement 2 L.NIVETHA AP/CSE,KNCET
  • 58. If(condition 1) { true statement – 1 } else if (condition – 2 ) { true statement – 2 } else { false statement – 2 } L.NIVETHA AP/CSE,KNCET
  • 59. #include<stdio.h> Void main() { int a,b,c; printf(“enter three values:”); scanf(“%d%d%d”,&a,&b,&c); if(a>b)&&(a>c) { printf(“a is biggest number”); } else if(b>c) { printf(“b is biggest number”); } else { printf(“c is biggest number”); } L.NIVETHA AP/CSE,KNCET
  • 60.  The if…else statement contain more than two are three if…else statement with in this called nested if….else statement.  (Or) it is called as if …else ladder. true false true false true false conditi on1 Condition 3 conditi on2 True statement 1 True statement 2 True statement 3 False statement 3 L.NIVETHA AP/CSE,KNCET
  • 61. Write a c program to check whether the given number is +ve or _ve Or zero. #include<stdio.h> #include<conio.h> Void main() { int num; printf(“Enter the number”); scanf(“%d”, &num); clrscr(); if(num==0) printf(“The number is zero”); else if(num>0) printf(“+ve number ”); else if(num<0) printf(“-ve number ”); else printf(“Enter valid number ”); return(o); getch(); } L.NIVETHA AP/CSE,KNCET
  • 62. It is a multi way decision statement , Using the value of a given variable and it check with case values, if it found execute those block of values , if not found it execute default statement. L.NIVETHA AP/CSE,KNCET
  • 64. SIMULATING SIMPLE CALCULATOR: #include<stdio.h> #include<conio.h> Void main() { Int n1,n2; Char op; Printf (“enter the expression”); Scanf(“ %d%c%d ”, &n1,&op,&n2); Switch(op) { case ‘ + ’ : printf( “%d” ,n1+n2); break; Case ‘ - ’ : printf( “%d” ,n1-n2); break; Case ‘ * ’ : printf( “%d” ,n1*n2); break; Case ‘ / ’: printf( “%d” ,n1/n2); break; default: printf(“invalid operator”) } } L.NIVETHA AP/CSE,KNCET
  • 65. The jump statement transfer the control from one point to another point without checking any condition. The following jump statement used in C language. 1. goto statement 2. break statement 3. Continue statement 4. return statement L.NIVETHA AP/CSE,KNCET
  • 66. goto statement:  The goto statement are used to transfer the control unconditionally from one point to another point with in the function.  It provide a highly unstructured way of transferring the program control from one point to another point.  It often makes the program control difficult to understand and modify. Syntax: goto label; L.NIVETHA AP/CSE,KNCET
  • 67.  The goto statement is always used in joining with an identifier-labeled statement.  The goto statement at the time of execution transfers the program control to an identifier-labeled statement, The label name used in the goto statement .  The goto statement can be used to make a forward jump as well as backward jump.  The goto statement transfer control any where with in the function, but it no way to take the control out of the function. L.NIVETHA AP/CSE,KNCET
  • 68. Forward jump: goto label; …………….. …………….. label; Statement backward jump: Label; statement; …………. …………. goto label; L.NIVETHA AP/CSE,KNCET
  • 69.  Break is a loop control statement .  The break statement is used to terminate the loop  when the break statement enter inside a loop ,then the loop is exit immediately  The break statement can be used in both while and for loop. L.NIVETHA AP/CSE,KNCET
  • 71. Example: #include<stdio.h> Void main() { int i; for(i=0; i<=5;i++) { if(i==3) { break; } printf(“Hai”); } } L.NIVETHA AP/CSE,KNCET
  • 72.  The continue statement rejects all the remaining statements in the current iteration of the for loop  and moves the control back to the top of the loop.  When the statement continue is entered into any C loop control automatically passes to the beginning of the loop L.NIVETHA AP/CSE,KNCET
  • 75.  The return statement terminate the execution of a function  It returns the control to the calling function.  A return statement without an expression can appear only in a function whose return type is void.  Example : return(); Or return(expression); L.NIVETHA AP/CSE,KNCET
  • 76. The loop is defined as the block of statements which are repeatedly executed for a certain number of time. 1. while statement(entry check loop)(top tested loop). 2. Do while statement(bottom tested loop)(exit check loop). 3. for statement. L.NIVETHA AP/CSE,KNCET
  • 77. The while loop is an entry controlled loop statement ,It means the condition is evaluated first , if it is true repeatedly execute the body of the loop until the condition become false. Syntax: false while(condition) { true ……. body of the loop; ……. } conditio n Body of the loop L.NIVETHA AP/CSE,KNCET
  • 78. #include<stdio.h> Void main() { Int n,I,sum=0; n =5; i=1; While(n>=i) sum=sum+i; i=i+1; Printf(“%d”, sum); } L.NIVETHA AP/CSE,KNCET
  • 79. The do…while statement is exit control statement , Here the body of the statement executed one’s after that check the condition. Syntax: do { …… body of the loop; true …… } while (condition) false Body of the loop conditio n L.NIVETHA AP/CSE,KNCET
  • 80. Example program: #include<stdio.h> void main() { int i=1, sum=0, n; n=5 do { sum=sum+i; i=i+1; } while(n>=i) printf(“the sum of 5 is:%d”, sum); } L.NIVETHA AP/CSE,KNCET
  • 81. This is another one of looping structure, it is execute set of instructions repeatedly until the condition become false. Syntax: for(initialization sec ;condition checking ; increment / decrement) { …… body of the loop; …… true } Initialization Increment / decrement Body of the loop conditio n L.NIVETHA AP/CSE,KNCET
  • 82. #include<stdio.h> Void main() { int n, i, sum=0; printf("Enter n value "); scanf("%d" , &n); for(i=1;n>=i ; i++) { sum=sum +i; } printf("%d", sum); } L.NIVETHA AP/CSE,KNCET
  • 83. A constant is an entity whose value remains the same throughout the execution of a program. Constant are classified as: 1. Literal constant 2. Qualified constant 3. Symbolic Constant L.NIVETHA AP/CSE,KNCET
  • 84. literal constants Floating point literal constant Integer literal constant Character literal constant Numeric literal constant String literal constant Character literal constant L.NIVETHA AP/CSE,KNCET
  • 85. 1. Integer literal constant:  It is formed with the use of sequence of digit without decimal point , that is .  Decimal digit - 0 to 9  Octal digit - 0 to 7  Hexadecimal digit - 0 to 9 A, B, C, D, E, F Rules:  It must be contain one digit  Decimal point not allowed,  It can either negative or positive,  Range is -32,768 to +32, 767.  No special character and blank spaces allowed with in an integer literals EXAMPLE: int mark=90 , avg=75 , total=10A1; L.NIVETHA AP/CSE,KNCET
  • 86. 2. Real constant: It contain sequence of digits with decimal point. Rules:  It must be contain one decimal digit  It can either negative or positive,  Range is -32,768 to +32, 767.  No special character and blank spaces allowed with in an float literals Example: float distance =120.8; L.NIVETHA AP/CSE,KNCET
  • 87. Character literal constant: 1. Single character literal constant: The character constant contain single character with in single quotes. Syntax: data type variable= ‘ single character ‘; Example: char initial= ‘ s ‘ ; 2. String literal constant: The string constant contains more than set of character with in double quotes. Syntax: data type variable= “ string “; Example: char department[5]=“IT”; L.NIVETHA AP/CSE,KNCET
  • 88. Qualified constant are created by using const keyword . Example: const char a=‘s’; const int a=10; if we declare normal variable and assign 10, like int a = 10; then this variable allocate 2byte memory space and store 10 with In those space. consider the statement const int a =10; the usage of qualified constant is after storing value 10 those memory block is locked, also could not allow new value with in this. L.NIVETHA AP/CSE,KNCET
  • 89. Symbolic constant are created with the help of the #define preprocessor. Example : #define pi 3.14 Here pi is a symbolic constant or called as macro constant. L.NIVETHA AP/CSE,KNCET
  • 90. A type qualifier cannot affect the range of the values, but affect the arithmetic properties of the declared object. There are two types: 1. Const - declaring an object by using const then that value cannot be modified during the execution. 2. Volatile – this object has some special properties. L.NIVETHA AP/CSE,KNCET
  • 91. Declaring a variable as volatile: Volatile data also one of constant data, it’s value modified only with in the program, also we could not change from external. Syntax: volatile data type variable=constant ; Example: volatile int year=2007 ; L.NIVETHA AP/CSE,KNCET
  • 92. A type modifier modifies the range of the object. There are following types: 1. Signed ( negative number ) 2. Unsigned ( zero or positive number ) 3. Short 4. Long L.NIVETHA AP/CSE,KNCET
  • 93. Short , long , signed , unsigned. Data type Size in bytes Control string Char signed and unsigned 1 %c Int signed 2 %d Unsigned int 2 %u Signed short int Unsigned short int 1 %d Long int 4 %id Unsigned long int 4 %iu float 4 %f double 8 %if Long double 10 %if L.NIVETHA AP/CSE,KNCET
  • 94. #include<stdio.h> #include<conio.h> #include<math.h> Void main() { int a, b ,c,first; printf(“Enter three numbers a,b,c”); scanf( “ %d%d%d”, &a,&b,&c); First=-b+sqrt((b*b-4*a*c)/(2*a)); printf(“%d”, first); } L.NIVETHA AP/CSE,KNCET
  • 95. #include<stdio.h> #include<conio.h> Int main() { int num; printf(“Enter a number ”)’ scanf(“%d”, &num); if((num%2)==0) printf(“Given number is even”); else Printf(“Given number is odd”); return(0); } L.NIVETHA AP/CSE,KNCET