SlideShare uma empresa Scribd logo
1 de 130
C
C is a powerful,flexible,portable and elegantly
structured programming language.
The creation of c programming language is
credited to Dennis Ritchie(sep.1941-oct.2011)
History of C
 C is a programming language.
C is a structured, high level language,
Machine independent language.
C was evolved from ALGOL,BCPL and B by
Dennis Ritchie at the Bell Laboratories in
1972.
C is running under a variety of operating
system and hardware platforms.
IMPORTANCE OF C
Programs written in c are efficient and fast.
This is due to its variety of datatypes and
powerful operators.
Several standard functions are available.
C is highly portable.
C language is well suited for structured
programming.
General Form
main() /* Function name
{ /* Start of program
------------------
------------------ /* program statements
------------------
} /*End of program
Sample program
main()
{
/*--------printing begins-------------*/
printf (“WELCOME”);
/*----------printing ends--------*/
}
OUTPUT
WELCOME
Main Function
 main()
 int main()
 void main()
 main(void)
 void main(void)
 int main(void)
Sample program 2: ADDING Two Numbers
/* Program ADDITION
main()
{
int number;
float amount;
number=100;
amount=30.75+75.35;
printf(“ %d n ”, number);
printf(“%5.2f”,amount);
}
OUTPUT
100
106.10
Use of math function
 #include<math.h>
#define PI 3.14
#define MAX 50
Main()
{
int angle;
Float x,y;
angle=0;
printf (“ angle Cos(angle)nn”);
While(angle<=MAX)
{
x=(PI/MAX)*angle;
y=cos(x);
Printf(“%15d %13.4fn”,angle,y);
OUTPUT
Angle Cos(angle)
0 1.0000
10 0.9848
20 0.9397
30 0.8660
40 0.7660
50 0.6428
Basic structure of c programs
Documentation Section
Link Section
Definition Section
Global Declaration Section
Main() function Section
{
}
Declaration Part
Executable Part
05-09-2017
Subprogram section
Function 1
Function 2
-
-
Function n
LETTERS
, Comma & ampersand
. Period ^ caret
; semicolon * asterisk
: colon - minus sign
? Question mark + plus sign
! Exclamation Mark / slash
 backslash ( left parenthesis
) right parenthesis ~ tilde
_ Underscore { left brace
} right brace
White spaces
Blank spaces
Horizontal tab
Carriage return
New line
Form feed
C Tokens
Operators
Special
symbols
StringsConstant
s
identifier
s
keywords
• Every C word is classified as either a keyword
or an identifier .
• All keywords have fixed meanings and these
meaning cannot be changed.
• Keywords serve as basic building blocks for
program statements.
auto double int struct
Break
Case
Char
Const
Continue
Default
do
Else
Enum
Extern
Float
For
Goto
if
Long
Register
Return
Short
Signed
Sizeof
static
Switch
Typedef
Union
Unsigned
Void
Volatile
while
ANSI C Keyword
CONSTANTS
 Constants in C refers to fixed values that do not
changes during the execution of a program.
constants
Numeric constants
Character constants
Integer
constants
Real
constants
Single
character
constant
String constants
Integer constants
 An Integer constant refers to a sequence of digits.
 There are three types of integer,namely
I. Decimal integer
ii. Octal integer
iii. Hexadecimal integer
Decimal integer
Decimal integers consists of a set of digits,0
through 9,preceded by an optional – or + sign.
Eg:
123 -321 0 654321 +78
Octal integer:
An octal integer constants consists of any
combination of digits from the 0 through 7,with a
leading 0.
Eg:
037 0 0435 0551
Real constant
Integer numbers are inadequate to represent
quantities that vary continuously, such as distances,
heights,temperatures,prices,and so on.
These quantities are represented by numbers
containing fractional parts like 17.548.such numbers
are called Real(or floating point)constants.
 Eg:
0.0083 -0.75 435.36+247.0
SINGLE CHARACTER CONSTANTS
 A single character constant(or simply character
constant)contains a single character enclosed within a
pair of single quotes marks.
Eg:
‘5’ ‘X’ ‘;’ ‘’
String Constants
A string constants is a sequence of characters enclosed
in double quotes.
The characters may be letters,numbers,special
characters and blank spaces.
Eg:
“Hello” “1987” “WELLDONE” “?....1” “5+3” “X”
Backslash character constants
 C supports some special backslash character constants
that are used in output function.
Eg:
The symbol ’n’ stands for newline character.
BACKSLASH CHARACTER CONSTANTS
Constant Meaning
‘b’
‘n’
‘r’
‘t’
‘”
‘’”
‘?’
‘’
‘10’
Back space
New line
Carriage return
Horizontal tab
Single quote
Double quote
Question mark
Back slash
Null
VARIABLES
 A variable is a data name that may be used to store
a data value.
 A variable name can be chosen by the programmer
in a meaningful way so as to reflect its function or
nature in the program.
Eg:
Average
Height
Total
Counter_1
Variables names may consists of letters,digits,and
underscore(_)character,subject to the following conditions:
 They must begin with a letter. Some system permit
underscore as the first character.
 ANSI standard recognizes a length of 31
characters.However,length should not be normally
more than eight character,since only the first eight
characters are treated as significant by many
compliers.
 Uppercase and lowercase are significant.That is,the
variable Total is not the same as total or TOTAL.
 It should not be a keyword.
 White space is not allowed.
C language is rich in its data types.
 ANSI C support three classes of data types
I, Primary(or fundamental)data types.
ii, Derived data types
iii, User defined data types.
All C compilers support five fundamental data types,
namely
I, integer ( int)
ii, character(char)
iii,floating point(float)
iv,double precision floating point(double)
v,void
INTEGER TYPES
 Integer are whole numbers with a range of values
supported by a particular machine.
 C has three classes of integer storange,namely
I,short int
ii,long
iii,int
Short int
int
Long int
Floating point types
 Floating point(or real)number are stored in 32 bits (on
all 16 bit and 32 bit machines),with 6 digits of
precision.
 Floating oint numbers are defined in C by the keyword
float.
float
double
Long double
VOID TYPES
 The Void type has no values.This is usually
used to specify the type of function.
The type of a function is said to be void when
it does not return any value to the calling
function.
CHARACTER DATATYPES
A single character can be defined as a
Character(char)type data.
Characters are usually stored in 8 bits (one byte)of
internal storage.
The qualifier Signed or unsigned may be explicitly
applied to char.
While unsigned chars have between 0 and
255,signed chars have values from -128 to 127
DECLARATION OF VARIABLES
 After designing suitable variable names,we must
declare them to the complier.Declaration does two
things:
i.Its tells the complier what the variable name is.
ii, its specifies what type of data the variable will
hold.
The declaration of variables must be done before they
are used in the program.
PRIMARY TYPE DECLARATION
 A variable can be used to store a value of any data
type.That is,the name has nothing to do with its type.
Syntax:
data-type v1,v2,…….vn;
v1,v2…..vn are the names of variables. Variables are
separated by commas.
A declaration statement must end with a semicolon.
Eg;
Int count;
Int number,total;
double ratio;
Declaration of variables
Main() /*……program name…….*/
{
/*……….Declaration……….*/
Float x,y;
Int code;
Short int count;
Long int amount;
Double deviation;
Unsigned n;
Char c;
/* ………computation…………..*/
………..
………..
DECLARATION OF STORAGE CLASS
 Storage class that provides information about
their location and visibility.
The storage class decides the portion of the
program within which the variables are
recognized.
/* Example Of Storage Class*/
Int m;
Main()
{
int i;
Float balance;
……..
……..
Function1()
}
Function1()
{
int i;
Float sum;
………
………
}
STORAGE CLASSES AND THEIR
MEANING
Storage
class
Meaning
Auto
Static
Extern
register
Local variable known only to the function in
which it is declared. Default is auto.
Local variable which exists and retains its value
even after the control is transferred to the calling
function.
Global variable known to all functions in the file.
Local variable which is stored in the register.
ASSIGNING VALUES TO VARIABLES
 Variables are created for use in program statements such
as
value=amount+inrate*amount;
while (year<=PERIOD)
{
……..
……..
Year=year+1;
}
program
Main()
{
Float x ,p;
Double y , q;
Unsigned k;
int m=54321;
Long int n=1234567890;
X=1.234567890000;
Y=9.87654321;
K=54321;
P=q=1.0;
printf(“m=%dn”,m);
printf(“n=%dn”,n);
printf(“x=%.121fn”,x);
printf(“x=%fn”,x);
printf(“y=%.121fn”,y);
printf(“y=%1fn”,y);
printf(“k=%u p=%f q=%.121fn”,k,p,q);
}
OUTPUT
M=-11215
N=1234567890
X=1.234567880630
X=1.234568
Y=9.876543210000
Y=9.876543
K=54321 p=1.00000 q=1.0000000000000
READING DATA FROM KEYBORAD
 Another way of giving values to variables is to input
through keyboard using the scanf
 its works much like an INPUT statement in BASIC.
The general format of scanf is as follows:
scanf(“control string”,&variable1,&variable2,….);
PROGRAM
Main()
{
int number;
printf (“Enter an integer numbern”);
Scanf(“%d”,&number);
If(number<100)
printf (”Your number is smaller than 100nn”);
else
printf(“your number contains more than two digitsn”);
}
OUTPUT
Enter an integer number
54
Your number is smaller than 1000
Enter an integer number
108
Your number contains more than two digits
Introduction
 An operator is a symbol that tells the computer to
perform certain mathematical or logical manipulation.
 Operators are used in programs to manipulate data
and variables.
 They usually form a part of the mathematical or logical
Expression.
C operators can be classified into a number of
categories.They include
1.Arithmetic operators.
2.Relational operators.
3.Logical operators.
4.Assignment operators.
5.Increment and decrement operators.
6.Conditional operators.
7.Bitwise operators.
8.Special operators.
Arithmetic operators
 C provides all the basic arithmetic operators.
 These can operate on any built in datatype allowed in
C.
Operator Meaning
+
-
*
/
%
Addition or unary plus
Subtraction or unary minus
Multiplication
Division
Modulo division
Types of arithmetic operators
1. Integer Arithmetic
2. Real Arithmetic
3. Mixed Mode Arithmetic
Integer Arithmetic
When both the operands in a single arithmetic
expression such as a+b are integer,the expression is
called an integer expression,
And the operation is called integer arithmetic. a=14
b=4
a-b=10
a+b=18
a*b=56
a/b=3
a%b=2
Integer arithmetic
Main()
{
int months,days;
Printf(“Enter daysn”);
Scanf(“%d”,&days);
months=days/30;
days=days%30;
Printf(“Months=%d Days=%d”,months,days);
}
output
Enter days
265
Months=8 Days=25
Enter days
364
Months=12 Days=4
Enter days
45
Months=1 Days=15
Real Arithmetic
 An arithmetic operation involving only real operands is
called real arithmetic.
 A real operand may assume values either in decimal or
exponential notation.
X=6.0/7.0=0.857143
y=1.0/3.0=0.333333
z=-2.0/3.0=-0.666667
The operator % cannot be used with real operands.
MIXED –MODE ARITHMETIC
 When one of the operands is real and the other is
integer,the expression is called a mixed –mode
arithmetic expression.
15/10.0=1.5
Whereas
15/10=1
RELATIONAL OPERATOR
 We may compare the age of two persons ,or the price of two items and so on.
These Comparisons can be done with the help of relational operators.
 An expression such as
a<b or 1<20
Containing a relation operator is termed as a reletional expression.
The value of a relation expression is either one or zero.its one if the specified
relation is true and zero If the relation is false.
10<20 is true
But
20<10 is false
RELATIONAL OPERATORS
Operator Meaning
<
<=
>
>=
==
!=
Is less than
Is less than or equal to
Is greater than
Is greater than or equal to
Is equal to
Is not equal to
LOGICAL OPERATORS
 C has the following three logical operators
&& meaning logical AND
|| meaning logical OR
! Meaning logical NOT
Truth table
Op-1 Op-2 Value of the expression
Op-1&&op-2 Op-1||op-2
1
1
0
0
1
0
1
0
1
0
0
0
1
1
1
0
ASSIGNMENT OPERATORS
 Assignment operators are used to assign the result of an
expression to a variable.
 Assignment operator is ,==.
 C has a set of ‘shorthand’ assignment operators of the
form
v op= exp;
Where V is a variable ,exp is an expression and
op is a C binary arithmetic operator.
The operator op= is known as the shorthand
assignment operator.
SHORTHAND ASSIGNMENT OPERATOR
Statement with simple
assignment operator
Statement with
shorthand operator
a=a+1
a=a-1
a=a*(n+1)
a=a/(n+1)
a=a%b
a+=1
a-=1
a*=n+1
a/=n+1
a%=b
PROGRAM
#define N 100
#define A 2
Main()
{
int a;
a=A;
While(a<N)
{
Printf(“%dn”,a);
a*=a;
}
}
OUTPUT
2
4
16
INCREMENT AND DECREMENT OPERATORS
 C allows two very useful operators not generally
found in other languages.
 These are the increment and decrement operators;
++ and –
Eg;
++m; or m++
-- m; or m—
CONDITIONAL OPERATORS
 A ternary operator pair ”?:” is available in C to
construct conditional expressions of the form
exp1?exp2:exp3
where exp1,exp2 and exp3 are expression
Eg
a=10;
b=15;
x=(a>b)?a:b;
BITWISE OPERATORS
 C has a distinction of supporting special
operators known as bitwise operator for
manipulation of data at bit level.
 Bitwise operators may not be applied to float or
double.
BITWISE OPERATORS
Operator meaning
&
|
^
<<
>>
Bitwise AND
Bitwise OR
Bitwise exclusive OR
Shift left
Shift right
SPECIAL OPERATORS
 C supports some special operators of interest
such as comma operator,Sizeof
operator,pointer operator (& and *) and
member selection operators.(.and ->).
The comma operator
 The comma operator can be used to link the related
expression together.
A comma-linked list of expressions are evaluated left
to right and the value of right-most expression is the
value of the combined expression.
Eg:
value =(x=10,y=5,x+y);
THE SIZEOF OPERATOR
 The sizeof is a compile time operator and ,when used
with an operand,it returns the numberof bytes the
operand occupies.
 Eg:
m=sizeof(sum);
n=sizeof(long int);
k=sizeof(235L);
ARITHMETIC EXPRESSION
An arithmetic expression is a combination of
variables,constants,and operators arranged as
per the syntax of the language.
EXPRESSION
Algebraic expression C expression
a×b-c
(m+n)(x+y)
(ab/c)
3x²+2x+1
(x/y)+c
a*b-c
(m+n)*(x+y)
a*b/c
3*x*x*2*x+1
x/y+c
EVALUATION OF EXPRESSIONS
 Expressions are evaluated using an assignment
statement of the form
variable=expression;
EVALUATION OF EXPRESSIONS
main()
{
float a,b,c,x,y,z;
a=9; b=12;c=3;
x=a-b/3+c*2-1;
y=a-b/(3+c)*(2-1);
z=a-(b/(3+c)*2)-1;
printf(“x=%fn”,x);
printf(“y=%fn”,y);
printf(“z=%fn”,z);
}
OUTPUT
x=10.000000
y= 7.000000
z= 4.000000
PRECEDENCE OF ARITHMETIC OPERATORS
 An expression without parentheses will be evaluated
from left to right using the rules of precedence of
operators.
 The are two distinct priority levels of arithmetic
operators in C.
High priority */%
Low priority +-
C language possesses such decision-making capabilities by
supporting the following statements.
1. if statement
2. switch statement
3. conditional operator statement
4. goto statement
These statement are popularly known as decision –
making statements.
IF STATEMENT
The if statement is a powerful decision –making
statement and is used to control the flow of execution of
statements.
General form:
if(test expression)
FLOW DIAGRAM
 entry
false
true
Test
exp?
THE DIFFERENT FORMS ARE
I. Simple if statement
II. if…..else statement
III. Nested if…..else statement
IV. Else if ladder
SIMPLE IF STATEMENT
The general form of a simple if statement is
if(test expression)
{
statement-block;
}
statement-x;
EXPLAIN
The ‘statement-block’ may be single statement or
group of statements or a group of statements.
if the test expression is true,the statement-block will
be executed.
otherwise the statement-block will be skipped and the
execution will jump to the statement-x
FLOW CHART OF SIMPLE IF CONTROL
entry
true
false
Test
exp?
Statement-
block
Statement-x
Next statement
PROGRAM
main()
{
int a,b,c,d;
float ratio;
printf (“Enter four integer valuesn”);
scanf (“%d%d%d%d”,&a,&b,&c,&d);
if(c-d!=0)/*Execute statement block */
{
ratio=(float)(a+b)/(float)(c-d);
printf(“Ratio=%fn”,ratio);
}
}
OUTPUT
Enter four integer values
12 23 34 45
Ratio=-3.181818
Enter four integer values
12 23 34 34
THE IF……ELSE STATEMENT
The if…else statement is an extension of the simple if
statement.
The general form is
if(test expression)
{
True-block statement(s)
}
else
{
false-block statement(s)
}
Statement-x
 If the test expression is ture block
satement(s),immediately following the if
statements are executed.
 Otherwise,the false-block statement(s) are
executed.
 In their case,either ture-block or false-block
will be excecuted,not both.
 In both the cases,the control is transferred
subsequently to the statement-X.
Flow chart of if ….else control
entry
true falseTest
exp?
True block
statement
False block
statement
Statement-X
Nesting of if….else statements
when a series of decisions are involved,we may have to use more than one
if…else statement.
General form:
if(test condition-1)
{
if(test condition-2);
{
statement-1;
}
else
{
statement-2;
}
}
else
{
Statement-3;
}
Tes
t
exp
1
Statement-3
Test
Exp
2?
Statement-2 Statement-1
Statement-x
Next
program
main()
{
float a,b,c;
printf(“enter th three valuesn”);
scanf(“%f %f%f”,&a,&b,&c);
printf(“n largest value is”);
if(a>b)
{
if(a>c)
printf(“%fn”,a);
else
printf(“%fn”,c);
}
else
{
if(c>b)
printf(“%fn”,c);
else
printf(“%fn”,b);
}
}
output
Enter three values
23445 67379 88843
Largest value is 88843.000000
The else if ladder
if(condition 1)
statement-1;
else if(condition 2)
statement-2;
else if(condition 3)
statement-3;
else if(condition n)
statement-n
else
default-statement;
Statement-x;

Conditi
on 1
Statement-1 Con
ditio
n 2
Statement-2
Conditi
on-n
Default
statement
Statement-n
Statement-x
The switch statement
General form
Switch(expression)
{
Case value-1:
block-1;
break;
Case value-2:
block-2
break;
Default:
default-block
break;
}
statement-x;
Switch statement
Switch
exp
block1
block2
Default
block
Statement-x
The ?: operator
This operator is a combination of ? and :, and takes
three operands.
This operator is popularly known as the Conditional
operator.
General form:
conditional expression?expresssion1:expression2
The conditional expression is evaluated first.
Decision making and looping
LOOP
A looping process,in general,would include the
following four steps:
 Setting and initialization of a condition variable.
 Execution of the statements in the loop.
 Test for a specified value of the condition variable
for execution of the loop.
 Incrementing or updating the condition variable.
The c language provides for three constructs for performing loop
operations.
They are:
i. The while statement
ii. The do statement
iii. The for statement
THE WHILE STATEMENT
The simplest of all the looping structures in C is the
while statement.
General form:
While (test condition)
{
body of the loop
}
The while is an entry controlled loop statement.
The test-condition is avaluated and if the condition is
true,then the body of the loop is executed.
After the execution of the body ,the test condition is once
again evaluated and if its true,the body is executed again.
program
main()
{
int count ,n;
float x,y;
printf(“Enter the values of x and n:”);
scanf(“%f%d”,&x and &n);
y=1.0;
count=1;
while(count<=n)
{
y=y*x;
count++;
}
Printf(“nx=%f;n=%d;x to power n=%fn”,x,n,y);
}
OUTPUT
Enter the values of x and n:2.5 4
x=2.500000;n=4; x to power n=39.062500
Enter the values of x and n: 0.5 4
x=0.500000;n=4; x to power n=0.062500
The DO statement
General form:
do
{
body of the loop
}
while(test-condition);
program
#define COLMAX 5
#define ROWMAX 5
main()
{
int row,column,y;
row=1;
printf(“Multiplication tablen”);
do
{
column=1;
do
{
y=row*column;
printf(“%4d”,y);
column=column+1;
}
while(column<=COLMAX);
printf(“n”);
row=row+1;
}
while(row<=ROWMAX);
}
output
MULTIPLICATION TABLE
-----------------------------------
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
THE FOR LOOPS
 The for loop is another entry-controlled loop that
provides a more concise loop control structure
 GENERAL MODEL
for(initialization;test-condition;increment)
{
body of the loop
}
For
while do
For(n=1;n<=10;++n)
{
-----------
-----------
-----------
}
n=1;
while(n<=10)
{
-----------
-----------
N=n+1;
n=1
do
{
-------------
-------------
N=n+1;
}
While(n<=10)
ARRAY
INTRODUCTION
An array is a fixed –size sequenced
collection of elements of the same data
types.
An array is a sequenced collection of
related data items that share the common
name.
TYPES OF ARRAY
1. One dimensional arrays
2. Two dimensional arrays
3. Multidimensional arrays
One dimensional arrays
A list of items can be given one variable name using only one
subscript and such a variable is called a Single subscripted
variable or a one dimensional array.
Eg
int number[5];
And the computer reserves five storage location as shown
below:
number[0]
number[1]
number[2]
number[3]
number[4]
The values to the array elements can be assigned
as follows :
Number[0]=35;
Number[1]=40;
Number[2]=20;
Number[3]=57;
Number[4]=19;
This would causes the array number to store
the values as shown below
number[0]
number[1]
number[2]
number[3]
number[4]
35
40
20
57
19
DECLARATION OF ONE DIMENTIONAL ARRAY
Array must be declared before they are used so that the
compiler can allocate space for them in memory.
The general form of array declaration is
type variable-name[size];
The type specifies the type of element that will be
contained in the array,such as int,float,or char and the
size indicates the maximum number of elements that
can be stored in the array.
Eg
float height[50];
program
main()
{
int i;
float x[3],value,total;
printf(“Enter the 3 real numbersn”);
for(i=0;i<3;i++)
{
scanf(“%f”,&value);
x[i]=value;
}
total=0.0;
for(i=0;i<3;i++)
printf(“n”);
for(i=o;i<3;i++)
printf(“x[%2d]=%5.2fn”,i+1,x[i]);
}
output
Enter 3 real numbers
1.1 2.2 3.3
x[1]=1.10
x[2]=2.20
x[3]=3.30
Initialization of one –dimensional
array
after an array is declared ,its elements must be
initialized.
 At compile time
 At run time
Compile time initialization
 We can initialize the elements the of arrary in the
same way as the ordinary variables when they are
declared.
 The general form:
type array-name[size]={list of values};
The values in the list are separated by commas.
Eg
int number[3]={0,0,0};
Run time initialization
an arrar can be explicitly initialized at run time.
This is approach usually applied for initializing large arrays.
eg
for(i=0;i<100;i+1)
{
if i<50
sum[i]=0.0;
else
sum[i]=1.0;
}
Two dimensional arrays
C allows us to define such tables of items by
using two dimensional arrays.
Two dimensional arrays are declared as
follows:
type array
_name[row_size][column_size];
INITIALIZING TWO DIMENSIONAL ARRAY
 Two-dimensional array may be initialized by
following their declaration with a list values
enclosed in braces.
Eg:
int table [2][3]={0,0,0,1,1,1};
The initialization is done row by row,
int table[2][3]={{0,0,0},{1,1,1}};
Multi -dimensional arrays
C allows array of three or more dimensions.The exact
limit is determined by the compiler.
The general form is:
type array_name[s1][s2][s3]…[sm];
sᵢ is the size of the i dimension
Eg:
int survey[3][5][12];
float table[5][4][5][3];
Introduction to C Programming Language
Introduction to C Programming Language

Mais conteúdo relacionado

Mais procurados

Programming in C Presentation upto FILE
Programming in C Presentation upto FILEProgramming in C Presentation upto FILE
Programming in C Presentation upto FILEDipta Saha
 
Structure of c_program_to_input_output
Structure of c_program_to_input_outputStructure of c_program_to_input_output
Structure of c_program_to_input_outputAnil Dutt
 
Introduction of c programming unit-ii ppt
Introduction of  c programming unit-ii pptIntroduction of  c programming unit-ii ppt
Introduction of c programming unit-ii pptJStalinAsstProfessor
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01Wingston
 
Chapter1 c programming data types, variables and constants
Chapter1 c programming   data types, variables and constantsChapter1 c programming   data types, variables and constants
Chapter1 c programming data types, variables and constantsvinay arora
 
Basic syntax : Algorithm,Flow chart
Basic syntax : Algorithm,Flow chartBasic syntax : Algorithm,Flow chart
Basic syntax : Algorithm,Flow chartPrasanna R Kovath
 
Basic Structure of C Language and Related Term
Basic Structure of C Language  and Related TermBasic Structure of C Language  and Related Term
Basic Structure of C Language and Related TermMuhammadWaseem305
 
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
 
Programming in C- Introduction
Programming in C- IntroductionProgramming in C- Introduction
Programming in C- Introductionsavitamhaske
 
Javascript by Yahoo
Javascript by YahooJavascript by Yahoo
Javascript by Yahoobirbal
 
best notes in c language
best notes in c languagebest notes in c language
best notes in c languageIndia
 
Basic C Programming language
Basic C Programming languageBasic C Programming language
Basic C Programming languageAbhishek Soni
 

Mais procurados (20)

C tutorial
C tutorialC tutorial
C tutorial
 
Clanguage
ClanguageClanguage
Clanguage
 
C fundamental
C fundamentalC fundamental
C fundamental
 
C programming
C programmingC programming
C programming
 
Programming in C Presentation upto FILE
Programming in C Presentation upto FILEProgramming in C Presentation upto FILE
Programming in C Presentation upto FILE
 
Structure of c_program_to_input_output
Structure of c_program_to_input_outputStructure of c_program_to_input_output
Structure of c_program_to_input_output
 
Introduction of c programming unit-ii ppt
Introduction of  c programming unit-ii pptIntroduction of  c programming unit-ii ppt
Introduction of c programming unit-ii ppt
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01
 
C tokens
C tokensC tokens
C tokens
 
Chapter1 c programming data types, variables and constants
Chapter1 c programming   data types, variables and constantsChapter1 c programming   data types, variables and constants
Chapter1 c programming data types, variables and constants
 
Basic syntax : Algorithm,Flow chart
Basic syntax : Algorithm,Flow chartBasic syntax : Algorithm,Flow chart
Basic syntax : Algorithm,Flow chart
 
Basic Structure of C Language and Related Term
Basic Structure of C Language  and Related TermBasic Structure of C Language  and Related Term
Basic Structure of C Language and Related Term
 
datatypes and variables in c language
 datatypes and variables in c language datatypes and variables in c language
datatypes and variables in c language
 
Programming in C- Introduction
Programming in C- IntroductionProgramming in C- Introduction
Programming in C- Introduction
 
Javascript by Yahoo
Javascript by YahooJavascript by Yahoo
Javascript by Yahoo
 
best notes in c language
best notes in c languagebest notes in c language
best notes in c language
 
C material
C materialC material
C material
 
C notes for exam preparation
C notes for exam preparationC notes for exam preparation
C notes for exam preparation
 
Basic C Programming language
Basic C Programming languageBasic C Programming language
Basic C Programming language
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
 

Semelhante a Introduction to C Programming Language

unit2.pptx
unit2.pptxunit2.pptx
unit2.pptxsscprep9
 
unit 1 cpds.pptx
unit 1 cpds.pptxunit 1 cpds.pptx
unit 1 cpds.pptxmadhurij54
 
C presentation book
C presentation bookC presentation book
C presentation bookkrunal1210
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C ProgrammingMOHAMAD NOH AHMAD
 
Msc prev updated
Msc prev updatedMsc prev updated
Msc prev updatedmshoaib15
 
Msc prev completed
Msc prev completedMsc prev completed
Msc prev completedmshoaib15
 
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
 
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
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniquesvalarpink
 
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
 
Unit 2 introduction to c programming
Unit 2   introduction to c programmingUnit 2   introduction to c programming
Unit 2 introduction to c programmingMithun DSouza
 

Semelhante a Introduction to C Programming Language (20)

C introduction
C introductionC introduction
C introduction
 
C language ppt
C language pptC language ppt
C language ppt
 
history of c.ppt
history of c.ppthistory of c.ppt
history of c.ppt
 
unit2.pptx
unit2.pptxunit2.pptx
unit2.pptx
 
unit 1 cpds.pptx
unit 1 cpds.pptxunit 1 cpds.pptx
unit 1 cpds.pptx
 
Cnotes
CnotesCnotes
Cnotes
 
C presentation book
C presentation bookC presentation book
C presentation book
 
Introduction%20C.pptx
Introduction%20C.pptxIntroduction%20C.pptx
Introduction%20C.pptx
 
Aniket tore
Aniket toreAniket tore
Aniket tore
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Msc prev updated
Msc prev updatedMsc prev updated
Msc prev updated
 
Msc prev completed
Msc prev completedMsc prev completed
Msc prev completed
 
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
 
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
 
C Language
C LanguageC Language
C Language
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniques
 
C notes
C notesC notes
C notes
 
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
 
Unit 2 introduction to c programming
Unit 2   introduction to c programmingUnit 2   introduction to c programming
Unit 2 introduction to c programming
 

Último

Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 

Último (20)

Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 

Introduction to C Programming Language

  • 1. C C is a powerful,flexible,portable and elegantly structured programming language. The creation of c programming language is credited to Dennis Ritchie(sep.1941-oct.2011)
  • 2. History of C  C is a programming language. C is a structured, high level language, Machine independent language. C was evolved from ALGOL,BCPL and B by Dennis Ritchie at the Bell Laboratories in 1972. C is running under a variety of operating system and hardware platforms.
  • 3. IMPORTANCE OF C Programs written in c are efficient and fast. This is due to its variety of datatypes and powerful operators. Several standard functions are available. C is highly portable. C language is well suited for structured programming.
  • 4. General Form main() /* Function name { /* Start of program ------------------ ------------------ /* program statements ------------------ } /*End of program
  • 5. Sample program main() { /*--------printing begins-------------*/ printf (“WELCOME”); /*----------printing ends--------*/ } OUTPUT WELCOME
  • 6. Main Function  main()  int main()  void main()  main(void)  void main(void)  int main(void)
  • 7. Sample program 2: ADDING Two Numbers /* Program ADDITION main() { int number; float amount; number=100; amount=30.75+75.35; printf(“ %d n ”, number); printf(“%5.2f”,amount); } OUTPUT 100 106.10
  • 8. Use of math function  #include<math.h> #define PI 3.14 #define MAX 50 Main() { int angle; Float x,y; angle=0; printf (“ angle Cos(angle)nn”); While(angle<=MAX) { x=(PI/MAX)*angle; y=cos(x); Printf(“%15d %13.4fn”,angle,y);
  • 9. OUTPUT Angle Cos(angle) 0 1.0000 10 0.9848 20 0.9397 30 0.8660 40 0.7660 50 0.6428
  • 10. Basic structure of c programs Documentation Section Link Section Definition Section Global Declaration Section Main() function Section { } Declaration Part Executable Part 05-09-2017
  • 12.
  • 14. , Comma & ampersand . Period ^ caret ; semicolon * asterisk : colon - minus sign ? Question mark + plus sign ! Exclamation Mark / slash backslash ( left parenthesis ) right parenthesis ~ tilde _ Underscore { left brace } right brace
  • 15. White spaces Blank spaces Horizontal tab Carriage return New line Form feed
  • 17. • Every C word is classified as either a keyword or an identifier . • All keywords have fixed meanings and these meaning cannot be changed. • Keywords serve as basic building blocks for program statements.
  • 18. auto double int struct Break Case Char Const Continue Default do Else Enum Extern Float For Goto if Long Register Return Short Signed Sizeof static Switch Typedef Union Unsigned Void Volatile while ANSI C Keyword
  • 19. CONSTANTS  Constants in C refers to fixed values that do not changes during the execution of a program. constants Numeric constants Character constants Integer constants Real constants Single character constant String constants
  • 20. Integer constants  An Integer constant refers to a sequence of digits.  There are three types of integer,namely I. Decimal integer ii. Octal integer iii. Hexadecimal integer
  • 21. Decimal integer Decimal integers consists of a set of digits,0 through 9,preceded by an optional – or + sign. Eg: 123 -321 0 654321 +78 Octal integer: An octal integer constants consists of any combination of digits from the 0 through 7,with a leading 0. Eg: 037 0 0435 0551
  • 22.
  • 23. Real constant Integer numbers are inadequate to represent quantities that vary continuously, such as distances, heights,temperatures,prices,and so on. These quantities are represented by numbers containing fractional parts like 17.548.such numbers are called Real(or floating point)constants.  Eg: 0.0083 -0.75 435.36+247.0
  • 24. SINGLE CHARACTER CONSTANTS  A single character constant(or simply character constant)contains a single character enclosed within a pair of single quotes marks. Eg: ‘5’ ‘X’ ‘;’ ‘’
  • 25. String Constants A string constants is a sequence of characters enclosed in double quotes. The characters may be letters,numbers,special characters and blank spaces. Eg: “Hello” “1987” “WELLDONE” “?....1” “5+3” “X”
  • 26. Backslash character constants  C supports some special backslash character constants that are used in output function. Eg: The symbol ’n’ stands for newline character.
  • 27. BACKSLASH CHARACTER CONSTANTS Constant Meaning ‘b’ ‘n’ ‘r’ ‘t’ ‘” ‘’” ‘?’ ‘’ ‘10’ Back space New line Carriage return Horizontal tab Single quote Double quote Question mark Back slash Null
  • 28. VARIABLES  A variable is a data name that may be used to store a data value.  A variable name can be chosen by the programmer in a meaningful way so as to reflect its function or nature in the program. Eg: Average Height Total Counter_1
  • 29. Variables names may consists of letters,digits,and underscore(_)character,subject to the following conditions:  They must begin with a letter. Some system permit underscore as the first character.  ANSI standard recognizes a length of 31 characters.However,length should not be normally more than eight character,since only the first eight characters are treated as significant by many compliers.  Uppercase and lowercase are significant.That is,the variable Total is not the same as total or TOTAL.  It should not be a keyword.  White space is not allowed.
  • 30.
  • 31. C language is rich in its data types.  ANSI C support three classes of data types I, Primary(or fundamental)data types. ii, Derived data types iii, User defined data types. All C compilers support five fundamental data types, namely I, integer ( int) ii, character(char) iii,floating point(float) iv,double precision floating point(double) v,void
  • 32. INTEGER TYPES  Integer are whole numbers with a range of values supported by a particular machine.  C has three classes of integer storange,namely I,short int ii,long iii,int Short int int Long int
  • 33. Floating point types  Floating point(or real)number are stored in 32 bits (on all 16 bit and 32 bit machines),with 6 digits of precision.  Floating oint numbers are defined in C by the keyword float. float double Long double
  • 34. VOID TYPES  The Void type has no values.This is usually used to specify the type of function. The type of a function is said to be void when it does not return any value to the calling function.
  • 35. CHARACTER DATATYPES A single character can be defined as a Character(char)type data. Characters are usually stored in 8 bits (one byte)of internal storage. The qualifier Signed or unsigned may be explicitly applied to char. While unsigned chars have between 0 and 255,signed chars have values from -128 to 127
  • 36. DECLARATION OF VARIABLES  After designing suitable variable names,we must declare them to the complier.Declaration does two things: i.Its tells the complier what the variable name is. ii, its specifies what type of data the variable will hold. The declaration of variables must be done before they are used in the program.
  • 37. PRIMARY TYPE DECLARATION  A variable can be used to store a value of any data type.That is,the name has nothing to do with its type. Syntax: data-type v1,v2,…….vn; v1,v2…..vn are the names of variables. Variables are separated by commas. A declaration statement must end with a semicolon. Eg; Int count; Int number,total; double ratio;
  • 38. Declaration of variables Main() /*……program name…….*/ { /*……….Declaration……….*/ Float x,y; Int code; Short int count; Long int amount; Double deviation; Unsigned n; Char c; /* ………computation…………..*/ ……….. ………..
  • 39. DECLARATION OF STORAGE CLASS  Storage class that provides information about their location and visibility. The storage class decides the portion of the program within which the variables are recognized.
  • 40. /* Example Of Storage Class*/ Int m; Main() { int i; Float balance; …….. …….. Function1() } Function1() { int i; Float sum; ……… ……… }
  • 41. STORAGE CLASSES AND THEIR MEANING Storage class Meaning Auto Static Extern register Local variable known only to the function in which it is declared. Default is auto. Local variable which exists and retains its value even after the control is transferred to the calling function. Global variable known to all functions in the file. Local variable which is stored in the register.
  • 42. ASSIGNING VALUES TO VARIABLES  Variables are created for use in program statements such as value=amount+inrate*amount; while (year<=PERIOD) { …….. …….. Year=year+1; }
  • 43. program Main() { Float x ,p; Double y , q; Unsigned k; int m=54321; Long int n=1234567890; X=1.234567890000; Y=9.87654321; K=54321; P=q=1.0; printf(“m=%dn”,m); printf(“n=%dn”,n); printf(“x=%.121fn”,x); printf(“x=%fn”,x); printf(“y=%.121fn”,y); printf(“y=%1fn”,y); printf(“k=%u p=%f q=%.121fn”,k,p,q); }
  • 45. READING DATA FROM KEYBORAD  Another way of giving values to variables is to input through keyboard using the scanf  its works much like an INPUT statement in BASIC. The general format of scanf is as follows: scanf(“control string”,&variable1,&variable2,….);
  • 46. PROGRAM Main() { int number; printf (“Enter an integer numbern”); Scanf(“%d”,&number); If(number<100) printf (”Your number is smaller than 100nn”); else printf(“your number contains more than two digitsn”); }
  • 47. OUTPUT Enter an integer number 54 Your number is smaller than 1000 Enter an integer number 108 Your number contains more than two digits
  • 48.
  • 49. Introduction  An operator is a symbol that tells the computer to perform certain mathematical or logical manipulation.  Operators are used in programs to manipulate data and variables.  They usually form a part of the mathematical or logical Expression.
  • 50. C operators can be classified into a number of categories.They include 1.Arithmetic operators. 2.Relational operators. 3.Logical operators. 4.Assignment operators. 5.Increment and decrement operators. 6.Conditional operators. 7.Bitwise operators. 8.Special operators.
  • 51. Arithmetic operators  C provides all the basic arithmetic operators.  These can operate on any built in datatype allowed in C. Operator Meaning + - * / % Addition or unary plus Subtraction or unary minus Multiplication Division Modulo division
  • 52. Types of arithmetic operators 1. Integer Arithmetic 2. Real Arithmetic 3. Mixed Mode Arithmetic
  • 53. Integer Arithmetic When both the operands in a single arithmetic expression such as a+b are integer,the expression is called an integer expression, And the operation is called integer arithmetic. a=14 b=4 a-b=10 a+b=18 a*b=56 a/b=3 a%b=2
  • 54. Integer arithmetic Main() { int months,days; Printf(“Enter daysn”); Scanf(“%d”,&days); months=days/30; days=days%30; Printf(“Months=%d Days=%d”,months,days); }
  • 55. output Enter days 265 Months=8 Days=25 Enter days 364 Months=12 Days=4 Enter days 45 Months=1 Days=15
  • 56. Real Arithmetic  An arithmetic operation involving only real operands is called real arithmetic.  A real operand may assume values either in decimal or exponential notation. X=6.0/7.0=0.857143 y=1.0/3.0=0.333333 z=-2.0/3.0=-0.666667 The operator % cannot be used with real operands.
  • 57. MIXED –MODE ARITHMETIC  When one of the operands is real and the other is integer,the expression is called a mixed –mode arithmetic expression. 15/10.0=1.5 Whereas 15/10=1
  • 58. RELATIONAL OPERATOR  We may compare the age of two persons ,or the price of two items and so on. These Comparisons can be done with the help of relational operators.  An expression such as a<b or 1<20 Containing a relation operator is termed as a reletional expression. The value of a relation expression is either one or zero.its one if the specified relation is true and zero If the relation is false. 10<20 is true But 20<10 is false
  • 59. RELATIONAL OPERATORS Operator Meaning < <= > >= == != Is less than Is less than or equal to Is greater than Is greater than or equal to Is equal to Is not equal to
  • 60. LOGICAL OPERATORS  C has the following three logical operators && meaning logical AND || meaning logical OR ! Meaning logical NOT
  • 61. Truth table Op-1 Op-2 Value of the expression Op-1&&op-2 Op-1||op-2 1 1 0 0 1 0 1 0 1 0 0 0 1 1 1 0
  • 62. ASSIGNMENT OPERATORS  Assignment operators are used to assign the result of an expression to a variable.  Assignment operator is ,==.  C has a set of ‘shorthand’ assignment operators of the form v op= exp; Where V is a variable ,exp is an expression and op is a C binary arithmetic operator. The operator op= is known as the shorthand assignment operator.
  • 63. SHORTHAND ASSIGNMENT OPERATOR Statement with simple assignment operator Statement with shorthand operator a=a+1 a=a-1 a=a*(n+1) a=a/(n+1) a=a%b a+=1 a-=1 a*=n+1 a/=n+1 a%=b
  • 64. PROGRAM #define N 100 #define A 2 Main() { int a; a=A; While(a<N) { Printf(“%dn”,a); a*=a; } }
  • 66. INCREMENT AND DECREMENT OPERATORS  C allows two very useful operators not generally found in other languages.  These are the increment and decrement operators; ++ and – Eg; ++m; or m++ -- m; or m—
  • 67. CONDITIONAL OPERATORS  A ternary operator pair ”?:” is available in C to construct conditional expressions of the form exp1?exp2:exp3 where exp1,exp2 and exp3 are expression Eg a=10; b=15; x=(a>b)?a:b;
  • 68. BITWISE OPERATORS  C has a distinction of supporting special operators known as bitwise operator for manipulation of data at bit level.  Bitwise operators may not be applied to float or double.
  • 69. BITWISE OPERATORS Operator meaning & | ^ << >> Bitwise AND Bitwise OR Bitwise exclusive OR Shift left Shift right
  • 70. SPECIAL OPERATORS  C supports some special operators of interest such as comma operator,Sizeof operator,pointer operator (& and *) and member selection operators.(.and ->).
  • 71. The comma operator  The comma operator can be used to link the related expression together. A comma-linked list of expressions are evaluated left to right and the value of right-most expression is the value of the combined expression. Eg: value =(x=10,y=5,x+y);
  • 72. THE SIZEOF OPERATOR  The sizeof is a compile time operator and ,when used with an operand,it returns the numberof bytes the operand occupies.  Eg: m=sizeof(sum); n=sizeof(long int); k=sizeof(235L);
  • 73. ARITHMETIC EXPRESSION An arithmetic expression is a combination of variables,constants,and operators arranged as per the syntax of the language.
  • 74. EXPRESSION Algebraic expression C expression a×b-c (m+n)(x+y) (ab/c) 3x²+2x+1 (x/y)+c a*b-c (m+n)*(x+y) a*b/c 3*x*x*2*x+1 x/y+c
  • 75. EVALUATION OF EXPRESSIONS  Expressions are evaluated using an assignment statement of the form variable=expression;
  • 76. EVALUATION OF EXPRESSIONS main() { float a,b,c,x,y,z; a=9; b=12;c=3; x=a-b/3+c*2-1; y=a-b/(3+c)*(2-1); z=a-(b/(3+c)*2)-1; printf(“x=%fn”,x); printf(“y=%fn”,y); printf(“z=%fn”,z); }
  • 78. PRECEDENCE OF ARITHMETIC OPERATORS  An expression without parentheses will be evaluated from left to right using the rules of precedence of operators.  The are two distinct priority levels of arithmetic operators in C. High priority */% Low priority +-
  • 79.
  • 80. C language possesses such decision-making capabilities by supporting the following statements. 1. if statement 2. switch statement 3. conditional operator statement 4. goto statement These statement are popularly known as decision – making statements.
  • 81. IF STATEMENT The if statement is a powerful decision –making statement and is used to control the flow of execution of statements. General form: if(test expression)
  • 83. THE DIFFERENT FORMS ARE I. Simple if statement II. if…..else statement III. Nested if…..else statement IV. Else if ladder
  • 84. SIMPLE IF STATEMENT The general form of a simple if statement is if(test expression) { statement-block; } statement-x;
  • 85. EXPLAIN The ‘statement-block’ may be single statement or group of statements or a group of statements. if the test expression is true,the statement-block will be executed. otherwise the statement-block will be skipped and the execution will jump to the statement-x
  • 86. FLOW CHART OF SIMPLE IF CONTROL entry true false Test exp? Statement- block Statement-x Next statement
  • 87. PROGRAM main() { int a,b,c,d; float ratio; printf (“Enter four integer valuesn”); scanf (“%d%d%d%d”,&a,&b,&c,&d); if(c-d!=0)/*Execute statement block */ { ratio=(float)(a+b)/(float)(c-d); printf(“Ratio=%fn”,ratio); } }
  • 88. OUTPUT Enter four integer values 12 23 34 45 Ratio=-3.181818 Enter four integer values 12 23 34 34
  • 89. THE IF……ELSE STATEMENT The if…else statement is an extension of the simple if statement. The general form is if(test expression) { True-block statement(s) } else { false-block statement(s) } Statement-x
  • 90.  If the test expression is ture block satement(s),immediately following the if statements are executed.  Otherwise,the false-block statement(s) are executed.  In their case,either ture-block or false-block will be excecuted,not both.  In both the cases,the control is transferred subsequently to the statement-X.
  • 91. Flow chart of if ….else control entry true falseTest exp? True block statement False block statement Statement-X
  • 92. Nesting of if….else statements when a series of decisions are involved,we may have to use more than one if…else statement. General form: if(test condition-1) { if(test condition-2); { statement-1; } else { statement-2; } } else { Statement-3; }
  • 94. program main() { float a,b,c; printf(“enter th three valuesn”); scanf(“%f %f%f”,&a,&b,&c); printf(“n largest value is”); if(a>b) { if(a>c) printf(“%fn”,a); else printf(“%fn”,c); } else { if(c>b) printf(“%fn”,c); else printf(“%fn”,b); } }
  • 95. output Enter three values 23445 67379 88843 Largest value is 88843.000000
  • 96. The else if ladder if(condition 1) statement-1; else if(condition 2) statement-2; else if(condition 3) statement-3; else if(condition n) statement-n else default-statement; Statement-x;
  • 97.  Conditi on 1 Statement-1 Con ditio n 2 Statement-2 Conditi on-n Default statement Statement-n Statement-x
  • 98. The switch statement General form Switch(expression) { Case value-1: block-1; break; Case value-2: block-2 break; Default: default-block break; } statement-x;
  • 100. The ?: operator This operator is a combination of ? and :, and takes three operands. This operator is popularly known as the Conditional operator. General form: conditional expression?expresssion1:expression2 The conditional expression is evaluated first.
  • 102. LOOP A looping process,in general,would include the following four steps:  Setting and initialization of a condition variable.  Execution of the statements in the loop.  Test for a specified value of the condition variable for execution of the loop.  Incrementing or updating the condition variable.
  • 103. The c language provides for three constructs for performing loop operations. They are: i. The while statement ii. The do statement iii. The for statement
  • 104. THE WHILE STATEMENT The simplest of all the looping structures in C is the while statement. General form: While (test condition) { body of the loop }
  • 105. The while is an entry controlled loop statement. The test-condition is avaluated and if the condition is true,then the body of the loop is executed. After the execution of the body ,the test condition is once again evaluated and if its true,the body is executed again.
  • 106. program main() { int count ,n; float x,y; printf(“Enter the values of x and n:”); scanf(“%f%d”,&x and &n); y=1.0; count=1; while(count<=n) { y=y*x; count++; } Printf(“nx=%f;n=%d;x to power n=%fn”,x,n,y); }
  • 107. OUTPUT Enter the values of x and n:2.5 4 x=2.500000;n=4; x to power n=39.062500 Enter the values of x and n: 0.5 4 x=0.500000;n=4; x to power n=0.062500
  • 108. The DO statement General form: do { body of the loop } while(test-condition);
  • 109. program #define COLMAX 5 #define ROWMAX 5 main() { int row,column,y; row=1; printf(“Multiplication tablen”); do { column=1; do { y=row*column; printf(“%4d”,y); column=column+1; } while(column<=COLMAX); printf(“n”); row=row+1; } while(row<=ROWMAX); }
  • 110. output MULTIPLICATION TABLE ----------------------------------- 1 2 3 4 5 2 4 6 8 10 3 6 9 12 15 4 8 12 16 20 5 10 15 20 25
  • 111. THE FOR LOOPS  The for loop is another entry-controlled loop that provides a more concise loop control structure  GENERAL MODEL for(initialization;test-condition;increment) { body of the loop }
  • 113. ARRAY
  • 114. INTRODUCTION An array is a fixed –size sequenced collection of elements of the same data types. An array is a sequenced collection of related data items that share the common name.
  • 115. TYPES OF ARRAY 1. One dimensional arrays 2. Two dimensional arrays 3. Multidimensional arrays
  • 116. One dimensional arrays A list of items can be given one variable name using only one subscript and such a variable is called a Single subscripted variable or a one dimensional array. Eg int number[5]; And the computer reserves five storage location as shown below: number[0] number[1] number[2] number[3] number[4]
  • 117. The values to the array elements can be assigned as follows : Number[0]=35; Number[1]=40; Number[2]=20; Number[3]=57; Number[4]=19;
  • 118. This would causes the array number to store the values as shown below number[0] number[1] number[2] number[3] number[4] 35 40 20 57 19
  • 119. DECLARATION OF ONE DIMENTIONAL ARRAY Array must be declared before they are used so that the compiler can allocate space for them in memory. The general form of array declaration is type variable-name[size]; The type specifies the type of element that will be contained in the array,such as int,float,or char and the size indicates the maximum number of elements that can be stored in the array. Eg float height[50];
  • 120. program main() { int i; float x[3],value,total; printf(“Enter the 3 real numbersn”); for(i=0;i<3;i++) { scanf(“%f”,&value); x[i]=value; } total=0.0; for(i=0;i<3;i++) printf(“n”); for(i=o;i<3;i++) printf(“x[%2d]=%5.2fn”,i+1,x[i]); }
  • 121. output Enter 3 real numbers 1.1 2.2 3.3 x[1]=1.10 x[2]=2.20 x[3]=3.30
  • 122. Initialization of one –dimensional array after an array is declared ,its elements must be initialized.  At compile time  At run time
  • 123.
  • 124. Compile time initialization  We can initialize the elements the of arrary in the same way as the ordinary variables when they are declared.  The general form: type array-name[size]={list of values}; The values in the list are separated by commas. Eg int number[3]={0,0,0};
  • 125. Run time initialization an arrar can be explicitly initialized at run time. This is approach usually applied for initializing large arrays. eg for(i=0;i<100;i+1) { if i<50 sum[i]=0.0; else sum[i]=1.0; }
  • 126. Two dimensional arrays C allows us to define such tables of items by using two dimensional arrays. Two dimensional arrays are declared as follows: type array _name[row_size][column_size];
  • 127. INITIALIZING TWO DIMENSIONAL ARRAY  Two-dimensional array may be initialized by following their declaration with a list values enclosed in braces. Eg: int table [2][3]={0,0,0,1,1,1}; The initialization is done row by row, int table[2][3]={{0,0,0},{1,1,1}};
  • 128. Multi -dimensional arrays C allows array of three or more dimensions.The exact limit is determined by the compiler. The general form is: type array_name[s1][s2][s3]…[sm]; sᵢ is the size of the i dimension Eg: int survey[3][5][12]; float table[5][4][5][3];

Notas do Editor

  1. word