You are on page 1of 94

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.
 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
‘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
 ‘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.
 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

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.

ANGURAJU.K 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
The tokens are referred as individual
text and punctuation in a passage of text.

C tokens

keyword constant strings Operato Special


Identifier
s s “college rs symbol
s
39 ” s
main() int + -
double 3.14 # $ %
Total
avg for

ANGURAJU.K AP/CSE - KNCET


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.

ANGURAJU.K 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’;

ANGURAJU.K 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.

ANGURAJU.K AP/CSE - KNCET


C data types
Primary User defined Derived Empty
Char typedef Arrays void
Int Enum Pointer
Float Structure function
double union

Data type Description Memory Control Example


bytes strings
int integer 2 bytes %d int a=20;
numbers
float Decimal 4 bytes %f float b=20.1
point
numbers
char Single 1 byte %c char s= ‘ n ‘;
character
double Double 8 bytes %if double
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

K.ANGURAJU , AP/CSE
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

K.ANGURAJU , AP/CSE
 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”;

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

ANGURAJU.K AP/CSE - KNCET


Short , long , signed , unsigned.
Data type Size in bytes Control
string
Char signed and 1 %c
unsigned
Int signed 2 %d

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:

ANGURAJU.K 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;

ANGURAJU.K 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

ANGURAJU.K AP/CSE - KNCET


The item whose value cannot change at
the time of execution are called constant.

‘C’ constants

Numeric Character
constant constant

Integer Character String constant


Real constant
constant constant

ANGURAJU.K 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;
ANGURAJU.K 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;

ANGURAJU.K 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 ;

ANGURAJU.K AP/CSE - KNCET


Delimeters:
Delimeters are symbols, it not perform any
operation, only it separate the variable and
statements.
#
,
:
;
()
[]
{}

ANGURAJU.K 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.

ANGURAJU.K 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 ;

ANGURAJU.K 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.
 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
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);
}

ANGURAJU.K 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

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” );
}

ANGURAJU.K 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)
ANGURAJU.K 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
#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.

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

ANGURAJU.K 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

ANGURAJU.K 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) ;
}

ANGURAJU.K 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

ANGURAJU.K AP/CSE - KNCET


Bitwise AND (&)
Here operate with two operand bit by bit.
Truth table for & is:
x= 7= 0000 0111 & 0 1
y= 8 = 0000 1000
0 0 0
OUTPUT: 0000 0000
1 0 1
Bitwise OR ( |)
x= 7= 0000 0111
| 0 1
y= 8 = 0000 1000
8421 0 0 1

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.

ANGURAJU.K 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.
K.ANGURAJU , AP/CSE
 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

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

ANGURAJU.K 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.
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.
‘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;

ANGURAJU.K 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”);
}
ANGURAJU.K AP/CSE - KNCET
1. If statement
2. If-else statement
3. Nested if- else statement
4. If-else ladder statement
5. Switch case statement
 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: condition
if(condition)
true false
{
True statement
true statements;
}

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”);
}
}

ANGURAJU.K 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) 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”);

ANGURAJU.K AP/CSE - KNCET


It is defined as we can write a entire if…
else statement in another if…else statement
called nesting.
Conditio
n1 true
false True
statement 1
Conditi
on 2

true false
true False
statement 2 statement 2

ANGURAJU.K AP/CSE - KNCET


If(condition 1)
{
true statement – 1
}
else if (condition – 2 )
{
true statement – 2
}
else
{
false statement – 2
}
#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”);
} ANGURAJU.K 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
conditi
on1

True statement
true conditi
on2
false1
Condition
True
3
statement 2 true
false True False
statement 3 statement 3

ANGURAJU.K 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();

}
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.

ANGURAJU.K AP/CSE - KNCET


Syntax:
switch(expression)
{
case constant1:
block1;
break;
case constant2:
block2;
break;
.
.
.
default:
default block;
break;
}
ANGURAJU.K AP/CSE - KNCET
SIMULATING SIMPLE Case ‘ - ’ :
CALCULATOR: printf( “%d” ,n1-n2);
#include<stdio.h> break;
#include<conio.h> Case ‘ * ’ :
Void main() printf( “%d” ,n1*n2);
{ break;
Int n1,n2; Case ‘ / ’:
Char op; printf( “%d” ,n1/n2);
Printf (“enter the break;
expression”); default:
Scanf(“ %d%c%d ”, printf(“invalid
&n1,&op,&n2); operator”)
Switch(op) }
{ }
case ‘ + ’ :
printf( “%d” ,n1+n2);
break;
ANGURAJU.K 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
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;
 The goto statement is always used in joining
with an identifier-labeled statement.

 Thegoto statement at the time of execution


transfers the program control to an
identifier-labeled statement, The label name
used in the goto statement .

 Thegoto 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.
Forward jump:
goto label;
……………..
……………..
label;
Statement
backward jump:
Label;
statement;
………….
………….
goto label;
 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.
Example:
#include<stdio.h>
Void main()
{
int i;
for(i=0; i<=5;i++)
{
if(i==3)
{
break;
}
printf(“Hai”);
}
}
 The continue statement rejects all the
remaining statements in the current iteration
of the for loop

 andmoves 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
for(i=0; i<=5;i++)
{
if(i==3)
{
continue;
}
printf(“Hai”);
}
}
 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);
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.

ANGURAJU.K 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: conditio
n
false
while(condition)
{ true
……. Body of the loop
body of the loop;
…….
}
ANGURAJU.K 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);
}
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
{
……
body of the loop; true
…… conditio
} n

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);
}

ANGURAJU.K 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
literal
constants

Numeric literal Character


constant literal constant

Integer literal Floating point Character String literal


constant literal constant literal constant constant

ANGURAJU.K 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;
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;

ANGURAJU.K 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”;
ANGURAJU.K 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.
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.
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.
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 ;
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
Short , long , signed , unsigned.
Data type Size in bytes Control
string
Char signed and 1 %c
unsigned
Int signed 2 %d

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);
}

You might also like