Professional Documents
Culture Documents
Source Execution
character set character set
Special Escape
Alphabets Digits White spaces
characters sequence
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.
function name.
Example:
auto , int , long , if , static , void …. etc
The tokens are referred as individual
text and punctuation in a passage of text.
C tokens
types.
K.ANGURAJU , AP/CSE
Definition:
Floating point type represent numbers with
K.ANGURAJU , AP/CSE
character is a single alphabet stored by using
single quotes.
string are represented as near by set of
char s=‘a’;
char name[20]=“ram”;
K.ANGURAJU , AP/CSE
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;
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
Unsigned int 2 %u
Signed short int 1 %d
Unsigned short int
Long int 4 %id
Unsigned long int 4 %iu
float 4 %f
double 8 %if
Long double 10 %if
ANGURAJU.K AP/CSE - KNCET
1. Type declaration:
syntax:
typedef data_type variable name;
Example:
typedef int mark;
mark m1,m2,m3;
2. Enumerated data type:
‘C’ constants
Numeric Character
constant constant
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 ;
operator.
The arithmetic operator available in c are.
+ - addition operator
- - subtraction operator
/ - Division operator
* - Multiplication operator
% - Modulo division operator
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);
}
logical operator.
&& logical AND –
it will execute set of statement if two
Syntax:
(exp1)&&(exp2)
Example:
(a>c)&&(a>b)
ANGURAJU.K AP/CSE - KNCET
|| logical OR
It will execute set of statement if any one of
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
#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”);
}
ANGURAJU.K AP/CSE - KNCET
Assignment operator used assign a values to a variable.
Compound assignment:
x+ =y x=x+y;
Nested assignment
Y=x=20
operator meaning
& Bitwise AND
| Bitwise OR
^ Bitwise XOR
<< Shift left
>> Shift right
~ One’s complement
OUTPUT:0000 1111 1 1 1
Bitwise exclusive OR (^)
^ 0 1
x= 7= 0000 0111
0 0 1
y= 8 = 0000 1000
1 1 0
OUTPUT: 0000 1111
ANGURAJU.K 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.
and division ( * , / , % )
The lowest precedence is addition and
subtraction.( + , -)
Operator with the same precedence are
K.ANGURAJU , AP/CSE
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
true or false.
Syntax: condition
if(condition)
true false
{
True statement
true statements;
}
Syantax:
if(condition) conditio
n
true
false
{
True False
true statement; statement statement
}
else
{
false statement;
}
ANGURAJU.K 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”);
true false
true False
statement 2 statement 2
true false
conditi
on1
True statement
true conditi
on2
false1
Condition
True
3
statement 2 true
false True False
statement 3 statement 3
}
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.
return();
Or return(expression);
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.
while (condition)
false
ANGURAJU.K 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);
} ANGURAJU.K 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)
{
…… Initialization
body of the loop; Increment /
…… decrement
true
} conditio Body of the
n loop
false
ANGURAJU.K 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);
}
Unsigned int 2 %u
Signed short int 1 %d
Unsigned short int
Long int 4 %id
Unsigned long int 4 %iu
float 4 %f
double 8 %if
Long double 10 %if
ANGURAJU.K 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);
}
#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);
}