SlideShare a Scribd company logo
Break From The Outermost Loop 
main( ) 
{ 
for ( i = 1 ; i <= 22 ; i+= 2 ) 
{ 
for ( j = 5 ; j <= 50 ; j++ ) 
{ 
for ( k = 1 ; k <= 9 ; k += 3 ) 
{ 
… … 
if ( i + j % k >= 2 ) 
break ; 
} 
} 
} 
} 
break ; 
break ; 
Go to work 
only once 
if ( i + j % k >= 2 ) 
if ( i + j % k >= 2 ) 
break ; 
break ;
main( ) 
{ 
for ( i = 1 ; i <= 22 ; i+= 2 ) 
{ 
for ( j = 5 ; j <= 50 ; j++ ) 
{ 
for ( k = 1 ; k <= 9 ; k += 3 ) 
{ 
… … 
if ( i + j % k >= 2 ) 
goto out ; 
} 
} 
} 
} 
Better Way... 
out : 
; 
Never use 
a goto
main( ) 
{ 
in : 
goto there ; 
for ( i = 1 ; i <= 22 ; i+= 2 ) 
{ 
for ( j = 5 ; j <= 50 ; j++ ) 
{ 
there : 
for ( k = 1 ; k <= 9 ; k += 3 ) 
{ 
… … 
if ( i + j % k >= 2 ) 
} goto out ; 
} 
} 
} 
Where Am I... 
out : 
goto in ;
Control Instructions 
 Sequence 
 Decision 
 Repitition 
 Case 
 goto
Communication 
main( ) 
{ 
int a = 10, b = 20, c = 30 ; 
calsum ( ) ; 
printf ( ”%d”, s ) ; 
} 
calsum( ) 
{ 
int a, b, c, s ; 
} 
int s ; 
s = a + b + c ; 
printf ( ”%d”, s ) ; 
Garbage 
Garbage
Passing Values 
main( ) 
{ 
Actual 
Arguments 
int a = 10, b = 20, c = 30 ; int s ; 
calsum ( a, b, c 
) ; 
printf ( ”%d”, s ) ; 
} 
calsum ( ) 
{ 
int s ; 
} 
int x, int y, int z 
s = x + y + z ; 
printf ( ”%d”, s ) ; 
Garbage 
Formal 
Arguments 
60
main( ) 
{ 
Returning Values 
int a = 10, b = 20, c = 30, s ; 
calsum ( a, b, c ) ; 
} 
calsum ( int x, int y, int z ) 
{ 
int ss ; 
ss = x + y + z ; 
return ( ss ) ; 
} 
s = calsum ( a, b, c ) ; 
printf ( ”%d”, s ) ; 
60 
return ; Returns only 
return ; Returns only 
control 
control 
Return control 
and value 
Return control 
and value 
return ( ss ) ; 
return ( 60 ) ; 
return ( x + y + z ) ;
Are These Calls OK? 
calsum ( a, 25, d ) ; 
calsum ( 10 + 2, 25 % 3, d ) ; 
calsum ( a, calsum ( 25, 10, 4 ), d ) ; 
d = calsum ( a, 25, d ) * calsum ( a, 25, d ) + 23 ; 
calsum ( int x, int y, int z ) 
{ 
int ss ; 
ss = x + y + z ; 
return ( ss ) ; 
} 
 
Nested calls are legal. 
Call within an expression are legal. 
Nested calls are legal. 
Call within an expression are legal.
Returning More Than 1 Value 
main( ) 
{ 
int a = 10, b = 20, c = 30 ; 
ssu, mp p=r soudm ( par, obd, c ( )a ;, b , c ) ; 
printf ( ”%d%d”, s, p ) ; 
} 
sumprod ( i n t x , i n t y , i n t z ) 
ss = x + y + z ; 
pp = x * y * z ; 
{ 
int ss, pp ; 
return ( ss, pp ) ; 
} 
int s, p ; 
 
 
A function can return only 
1 value at a time
main( ) 
{ 
One More Try 
int a = 10, b = 20, c = 30 ; 
int s, p ; 
s = sumprod ( a, b, c ) ; 
p = sumprod ( a, b, c ) ; 
printf ( ”%d%d”, s, p ) ; 
} sumprod ( int x, int y, int z ) 
{ 
ss = x + y + z ; 
pp = x * y * z ; 
return ( ss ) ; 
return ( pp ) ; 
} 
int ss, pp ; 
60 60 
Redundant
main( ) 
{ 
The Only Way Out 
int a = 10, b = 20, c = 30 ; int s, p ; 
s = sumprod ( a, b, c ) ; 
p = sumprod ( a, b, c ) ; 
printf ( ”%d%d”, s, p ) ; 
} 
, 1 
, 2 
sumprod ( int x, int y, int z, ) 
{ 
int ss, pp ; 
ss = x + y + z ; pp = x * y * z ; 
} 
int code 
if ( code == 1 ) 
return ( ss ) ; 
else 
return ( pp ) ; 
Sum, Product, 
Average, Variance 
Standard Deviation
A Better Way 
sumprod ( int x, int y, int z, int code ) 
{ 
int ss, pp ; 
ss = x + y + z ; 
pp = x * y * z ; 
} 
if ( code == 1 ) 
return ( ss ) ; 
else 
return ( pp ) ; 
code == 1 ? return ( x + y + z ) : return ( x * y * z ) ; 
return ( code == 1 ? x + y + z : x * y * z ) ;
ANSI V/s K  R 
calsum ( int x, int y, int z ) 
{ 
.. 
} 
calsum ( int x, int y, int z ) 
{ 
.. 
} 
calsum ( x, y, z ) 
int x, y, z ; 
{ 
.. 
} 
calsum ( x, y, z ) 
int x, y, z ; 
{ 
.. 
} 
ANSI 
Kernighan  
Ritchie
main( ) 
{ 
int y ; 
printf ( ”Enter year” ) ; 
scanf ( ”%d”, y ) ; 
romanize ( y ) ; 
} 
romanize ( int yy ) 
{ 
int n, i ; 
n = yy / 1000 ; 
for ( i = 1 ; i = n ; i ++ ) 
printf ( ”m” ) ; 
Decimal Roman 
1000 m 
500 d 
100 c 
50 l 
10 x 
5 v 
1 i 
} 
Roman Equivalent 
1998 m d c c c c l x x x x i i i 
1998 
v
A More General Call 
main( ) 
{ 
int y ; 
printf ( ”Enter year” ) ; 
scanf ( ”%d”, y ) ; 
, 1000 , ’m’ 
y romanize = romanise ( y ( y, 1000, ’) m’ ; 
) ; 
} 
romanize ( int yy , int j , char ch 
) 
{ 
int n, i ; 
n = yy / j ; 
for ( i = 1 ; i = n ; i ++ ) 
printf ( ) ; 
} 
”%c”, ch 
return ( yy % j ) ;
main( ) 
{ 
... 
1998 md c c c c lx xx x v i ii 
, ’m’ 
y = romanise ( y, 1000 ) ; 
y = romanise ( y, 500, ’d’ ) ; 
y = romanise ( y, 100, ’c’ ) ; 
y = romanise ( y, 50, ’l’ ) ; 
y = romanise ( y, 10, ’x’ ) ; 
y = romanise ( y, 5, ’v’ ) ; 
romanise ( y, 1, ’i’ ) ; 
} 
romanize ( int yy ) 
{ 
} 
, int j, char ch 
int n, i ; 
n = yy / j ; 
for ( i = 1 ; i = n ; i ++ ) 
printf ( ”%c”, ch ) ; 
return ( yy % j ) ; 
Works
Advanced Features of 
Functions 
 Returning a non-integer value 
 Call by value / Call by reference 
 Recursion
Returning a Non-Integer Value 
main( ) 
{ 
a = square ( 2.0 ) ; 
b = square ( 2.5 ) ; 
c = square ( 1.5 ) ; 
printf ( ” %f %f %f ”, a, b, c, ) ; 
square ( 2.0 ) ; 
} square ( ) float x 
{ 
float y ; 
y = x * x ; 
printf ( ” %f ”, y ) ; 
return ( y ) ; 
} 
Function 
Prototype 
4.0 6.0 2.0 
float a, b, c ; float square ( float ) ; 
4.0 
6.25 
2.25 
float square ( float x )
115566 -- 116611 ((ee))

More Related Content

What's hot

C++ TUTORIAL 6
C++ TUTORIAL 6C++ TUTORIAL 6
C++ TUTORIAL 6
Farhan Ab Rahman
 
Equation plane
Equation planeEquation plane
Equation plane
cmnell
 
Lec23-CS110 Computational Engineering
Lec23-CS110 Computational EngineeringLec23-CS110 Computational Engineering
Lec23-CS110 Computational Engineering
Sri Harsha Pamu
 
VTU Network lab programs
VTU Network lab   programsVTU Network lab   programs
VTU Network lab programs
Ananda Kumar HN
 
Monte-carlo sim pricing EU call
Monte-carlo sim pricing EU callMonte-carlo sim pricing EU call
Monte-carlo sim pricing EU callTianqi Huang, CFA
 
PYTHON. AM CALL Pricing Trees
PYTHON. AM CALL Pricing TreesPYTHON. AM CALL Pricing Trees
PYTHON. AM CALL Pricing TreesTianqi Huang, CFA
 
BCSL 058 solved assignment
BCSL 058 solved assignmentBCSL 058 solved assignment
Lcs & fractional knapsack
Lcs & fractional knapsackLcs & fractional knapsack
Lcs & fractional knapsack
Sajid Hasan
 
3. chapter ii
3. chapter ii3. chapter ii
3. chapter ii
Chhom Karath
 
C++ TUTORIAL 7
C++ TUTORIAL 7C++ TUTORIAL 7
C++ TUTORIAL 7
Farhan Ab Rahman
 
Program to reflecta triangle
Program to reflecta triangleProgram to reflecta triangle
Program to reflecta triangle
Tanya Makkar
 
Programa en C++ ( escriba 3 números y diga cual es el mayor))
Programa en C++ ( escriba 3 números y diga cual es el mayor))Programa en C++ ( escriba 3 números y diga cual es el mayor))
Programa en C++ ( escriba 3 números y diga cual es el mayor))Alex Penso Romero
 
PYTHON PROGRAMS FOR BEGINNERS
PYTHON PROGRAMS FOR BEGINNERSPYTHON PROGRAMS FOR BEGINNERS
PYTHON PROGRAMS FOR BEGINNERS
JEETPRATAPSINGH
 
Página 115
Página 115Página 115
ECMAScript 6 major changes
ECMAScript 6 major changesECMAScript 6 major changes
ECMAScript 6 major changeshayato
 

What's hot (19)

Vcs29
Vcs29Vcs29
Vcs29
 
C++ TUTORIAL 6
C++ TUTORIAL 6C++ TUTORIAL 6
C++ TUTORIAL 6
 
PythonArtCode
PythonArtCodePythonArtCode
PythonArtCode
 
Equation plane
Equation planeEquation plane
Equation plane
 
Lec23-CS110 Computational Engineering
Lec23-CS110 Computational EngineeringLec23-CS110 Computational Engineering
Lec23-CS110 Computational Engineering
 
VTU Network lab programs
VTU Network lab   programsVTU Network lab   programs
VTU Network lab programs
 
Monte-carlo sim pricing EU call
Monte-carlo sim pricing EU callMonte-carlo sim pricing EU call
Monte-carlo sim pricing EU call
 
PYTHON. AM CALL Pricing Trees
PYTHON. AM CALL Pricing TreesPYTHON. AM CALL Pricing Trees
PYTHON. AM CALL Pricing Trees
 
BCSL 058 solved assignment
BCSL 058 solved assignmentBCSL 058 solved assignment
BCSL 058 solved assignment
 
Vcs17
Vcs17Vcs17
Vcs17
 
Lcs & fractional knapsack
Lcs & fractional knapsackLcs & fractional knapsack
Lcs & fractional knapsack
 
3. chapter ii
3. chapter ii3. chapter ii
3. chapter ii
 
C++ TUTORIAL 7
C++ TUTORIAL 7C++ TUTORIAL 7
C++ TUTORIAL 7
 
Program to reflecta triangle
Program to reflecta triangleProgram to reflecta triangle
Program to reflecta triangle
 
Programa en C++ ( escriba 3 números y diga cual es el mayor))
Programa en C++ ( escriba 3 números y diga cual es el mayor))Programa en C++ ( escriba 3 números y diga cual es el mayor))
Programa en C++ ( escriba 3 números y diga cual es el mayor))
 
PYTHON PROGRAMS FOR BEGINNERS
PYTHON PROGRAMS FOR BEGINNERSPYTHON PROGRAMS FOR BEGINNERS
PYTHON PROGRAMS FOR BEGINNERS
 
programs
programsprograms
programs
 
Página 115
Página 115Página 115
Página 115
 
ECMAScript 6 major changes
ECMAScript 6 major changesECMAScript 6 major changes
ECMAScript 6 major changes
 

Viewers also liked

List build linked in - jigsaw - salesforce - free tools
List build   linked in - jigsaw - salesforce - free toolsList build   linked in - jigsaw - salesforce - free tools
List build linked in - jigsaw - salesforce - free tools
RWolfrum
 
Presentation Ukay Metal Ind.Pvt.Ltd.-Ashok 7-2015
Presentation Ukay Metal Ind.Pvt.Ltd.-Ashok  7-2015Presentation Ukay Metal Ind.Pvt.Ltd.-Ashok  7-2015
Presentation Ukay Metal Ind.Pvt.Ltd.-Ashok 7-2015
Ashok Chandak
 
Presentation ukay 2014 - ashok 05.2014
Presentation ukay 2014 - ashok  05.2014Presentation ukay 2014 - ashok  05.2014
Presentation ukay 2014 - ashok 05.2014
Ashok Chandak
 
Presentation ukay ashok 2-2015
Presentation ukay  ashok  2-2015Presentation ukay  ashok  2-2015
Presentation ukay ashok 2-2015
Ashok Chandak
 
Presentation ukay 2014 - ashok 17.02.2014
Presentation ukay 2014 - ashok  17.02.2014Presentation ukay 2014 - ashok  17.02.2014
Presentation ukay 2014 - ashok 17.02.2014
Ashok Chandak
 
RIM(Reaction Injection Moulding)
RIM(Reaction Injection Moulding)RIM(Reaction Injection Moulding)
RIM(Reaction Injection Moulding)
Ashok Chandak
 

Viewers also liked (17)

STACKS AND QUEUES CONCEPTS
STACKS AND QUEUES CONCEPTSSTACKS AND QUEUES CONCEPTS
STACKS AND QUEUES CONCEPTS
 
C languaGE UNIT-1
C languaGE UNIT-1C languaGE UNIT-1
C languaGE UNIT-1
 
Vcs12
Vcs12Vcs12
Vcs12
 
Vcs23
Vcs23Vcs23
Vcs23
 
Vcs4
Vcs4Vcs4
Vcs4
 
Vcs8
Vcs8Vcs8
Vcs8
 
Gincana
GincanaGincana
Gincana
 
B-TREE PREPARED BY M V BRAHMANANDA REDDY
B-TREE PREPARED BY M V BRAHMANANDA REDDYB-TREE PREPARED BY M V BRAHMANANDA REDDY
B-TREE PREPARED BY M V BRAHMANANDA REDDY
 
List build linked in - jigsaw - salesforce - free tools
List build   linked in - jigsaw - salesforce - free toolsList build   linked in - jigsaw - salesforce - free tools
List build linked in - jigsaw - salesforce - free tools
 
Presentation Ukay Metal Ind.Pvt.Ltd.-Ashok 7-2015
Presentation Ukay Metal Ind.Pvt.Ltd.-Ashok  7-2015Presentation Ukay Metal Ind.Pvt.Ltd.-Ashok  7-2015
Presentation Ukay Metal Ind.Pvt.Ltd.-Ashok 7-2015
 
Presentation ukay 2014 - ashok 05.2014
Presentation ukay 2014 - ashok  05.2014Presentation ukay 2014 - ashok  05.2014
Presentation ukay 2014 - ashok 05.2014
 
Presentation ukay ashok 2-2015
Presentation ukay  ashok  2-2015Presentation ukay  ashok  2-2015
Presentation ukay ashok 2-2015
 
C SLIDES PREPARED BY M V B REDDY
C SLIDES PREPARED BY  M V B REDDYC SLIDES PREPARED BY  M V B REDDY
C SLIDES PREPARED BY M V B REDDY
 
Vcs26
Vcs26Vcs26
Vcs26
 
Presentation ukay 2014 - ashok 17.02.2014
Presentation ukay 2014 - ashok  17.02.2014Presentation ukay 2014 - ashok  17.02.2014
Presentation ukay 2014 - ashok 17.02.2014
 
C PROGRAMS
C PROGRAMSC PROGRAMS
C PROGRAMS
 
RIM(Reaction Injection Moulding)
RIM(Reaction Injection Moulding)RIM(Reaction Injection Moulding)
RIM(Reaction Injection Moulding)
 

Similar to Vcs9

C tech questions
C tech questionsC tech questions
C tech questions
vijay00791
 
Lab Question
Lab QuestionLab Question
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
happycocoman
 
9.C Programming
9.C Programming9.C Programming
9.C Programming
Export Promotion Bureau
 
5th Sem SS lab progs
5th Sem SS lab progs5th Sem SS lab progs
5th Sem SS lab progs
Nagarjun Pakka Kannadiga
 
Blocks+gcd入門
Blocks+gcd入門Blocks+gcd入門
Blocks+gcd入門
領一 和泉田
 
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERS
KavyaSharma65
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
Nithin Kumar,VVCE, Mysuru
 
ADA FILE
ADA FILEADA FILE
ADA FILE
Gaurav Singh
 
Cpds lab
Cpds labCpds lab
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C Code
Syed Ahmed Zaki
 
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointersvinay arora
 
Recursion in C
Recursion in CRecursion in C
Recursion in C
Lakshmi Sarvani Videla
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
vrgokila
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
Azhar Javed
 

Similar to Vcs9 (20)

C tech questions
C tech questionsC tech questions
C tech questions
 
Lab Question
Lab QuestionLab Question
Lab Question
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
 
9.C Programming
9.C Programming9.C Programming
9.C Programming
 
5th Sem SS lab progs
5th Sem SS lab progs5th Sem SS lab progs
5th Sem SS lab progs
 
Blocks+gcd入門
Blocks+gcd入門Blocks+gcd入門
Blocks+gcd入門
 
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERS
 
Vcs5
Vcs5Vcs5
Vcs5
 
Vcs16
Vcs16Vcs16
Vcs16
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
Coding
CodingCoding
Coding
 
Struct examples
Struct examplesStruct examples
Struct examples
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C Code
 
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointers
 
Recursion in C
Recursion in CRecursion in C
Recursion in C
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 

More from Malikireddy Bramhananda Reddy

DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYMalikireddy Bramhananda Reddy
 
DATA STRUCTURES AND ALGORITHMS UNIT-3 TREES PREPARED BY M V BRAHMANANDA REDDY
DATA STRUCTURES AND ALGORITHMS UNIT-3 TREES PREPARED BY M V BRAHMANANDA REDDYDATA STRUCTURES AND ALGORITHMS UNIT-3 TREES PREPARED BY M V BRAHMANANDA REDDY
DATA STRUCTURES AND ALGORITHMS UNIT-3 TREES PREPARED BY M V BRAHMANANDA REDDYMalikireddy Bramhananda Reddy
 
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada ReddyDatastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada ReddyMalikireddy Bramhananda Reddy
 
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
C notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit orderC notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit order
C notes by m v b reddy(gitam)imp notes all units notes 5 unit orderMalikireddy Bramhananda Reddy
 

More from Malikireddy Bramhananda Reddy (20)

M v bramhananda reddy dsa complete notes
M v bramhananda reddy dsa complete notesM v bramhananda reddy dsa complete notes
M v bramhananda reddy dsa complete notes
 
AVL TREE PREPARED BY M V BRAHMANANDA REDDY
AVL TREE PREPARED BY M V BRAHMANANDA REDDYAVL TREE PREPARED BY M V BRAHMANANDA REDDY
AVL TREE PREPARED BY M V BRAHMANANDA REDDY
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
 
DATA STRUCTURES AND ALGORITHMS UNIT-3 TREES PREPARED BY M V BRAHMANANDA REDDY
DATA STRUCTURES AND ALGORITHMS UNIT-3 TREES PREPARED BY M V BRAHMANANDA REDDYDATA STRUCTURES AND ALGORITHMS UNIT-3 TREES PREPARED BY M V BRAHMANANDA REDDY
DATA STRUCTURES AND ALGORITHMS UNIT-3 TREES PREPARED BY M V BRAHMANANDA REDDY
 
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada ReddyDatastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
 
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDYC LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
 
DATASTRUCTURES UNIT-1
DATASTRUCTURES UNIT-1DATASTRUCTURES UNIT-1
DATASTRUCTURES UNIT-1
 
Data representation UNIT-1
Data representation UNIT-1Data representation UNIT-1
Data representation UNIT-1
 
C AND DATASTRUCTURES PREPARED BY M V B REDDY
C AND DATASTRUCTURES PREPARED BY M V B REDDYC AND DATASTRUCTURES PREPARED BY M V B REDDY
C AND DATASTRUCTURES PREPARED BY M V B REDDY
 
C LANGUAGE NOTES
C LANGUAGE NOTESC LANGUAGE NOTES
C LANGUAGE NOTES
 
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
C notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit orderC notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit order
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
 
Vcs28
Vcs28Vcs28
Vcs28
 
Vcs24
Vcs24Vcs24
Vcs24
 
Vcs22
Vcs22Vcs22
Vcs22
 
Vcs21
Vcs21Vcs21
Vcs21
 
Vcs20
Vcs20Vcs20
Vcs20
 
Vcs19
Vcs19Vcs19
Vcs19
 
Vcs15
Vcs15Vcs15
Vcs15
 
Vcs14
Vcs14Vcs14
Vcs14
 
Vcs6
Vcs6Vcs6
Vcs6
 

Vcs9

  • 1. Break From The Outermost Loop main( ) { for ( i = 1 ; i <= 22 ; i+= 2 ) { for ( j = 5 ; j <= 50 ; j++ ) { for ( k = 1 ; k <= 9 ; k += 3 ) { … … if ( i + j % k >= 2 ) break ; } } } } break ; break ; Go to work only once if ( i + j % k >= 2 ) if ( i + j % k >= 2 ) break ; break ;
  • 2. main( ) { for ( i = 1 ; i <= 22 ; i+= 2 ) { for ( j = 5 ; j <= 50 ; j++ ) { for ( k = 1 ; k <= 9 ; k += 3 ) { … … if ( i + j % k >= 2 ) goto out ; } } } } Better Way... out : ; Never use a goto
  • 3. main( ) { in : goto there ; for ( i = 1 ; i <= 22 ; i+= 2 ) { for ( j = 5 ; j <= 50 ; j++ ) { there : for ( k = 1 ; k <= 9 ; k += 3 ) { … … if ( i + j % k >= 2 ) } goto out ; } } } Where Am I... out : goto in ;
  • 4. Control Instructions Sequence Decision Repitition Case goto
  • 5. Communication main( ) { int a = 10, b = 20, c = 30 ; calsum ( ) ; printf ( ”%d”, s ) ; } calsum( ) { int a, b, c, s ; } int s ; s = a + b + c ; printf ( ”%d”, s ) ; Garbage Garbage
  • 6. Passing Values main( ) { Actual Arguments int a = 10, b = 20, c = 30 ; int s ; calsum ( a, b, c ) ; printf ( ”%d”, s ) ; } calsum ( ) { int s ; } int x, int y, int z s = x + y + z ; printf ( ”%d”, s ) ; Garbage Formal Arguments 60
  • 7. main( ) { Returning Values int a = 10, b = 20, c = 30, s ; calsum ( a, b, c ) ; } calsum ( int x, int y, int z ) { int ss ; ss = x + y + z ; return ( ss ) ; } s = calsum ( a, b, c ) ; printf ( ”%d”, s ) ; 60 return ; Returns only return ; Returns only control control Return control and value Return control and value return ( ss ) ; return ( 60 ) ; return ( x + y + z ) ;
  • 8. Are These Calls OK? calsum ( a, 25, d ) ; calsum ( 10 + 2, 25 % 3, d ) ; calsum ( a, calsum ( 25, 10, 4 ), d ) ; d = calsum ( a, 25, d ) * calsum ( a, 25, d ) + 23 ; calsum ( int x, int y, int z ) { int ss ; ss = x + y + z ; return ( ss ) ; } Nested calls are legal. Call within an expression are legal. Nested calls are legal. Call within an expression are legal.
  • 9. Returning More Than 1 Value main( ) { int a = 10, b = 20, c = 30 ; ssu, mp p=r soudm ( par, obd, c ( )a ;, b , c ) ; printf ( ”%d%d”, s, p ) ; } sumprod ( i n t x , i n t y , i n t z ) ss = x + y + z ; pp = x * y * z ; { int ss, pp ; return ( ss, pp ) ; } int s, p ; A function can return only 1 value at a time
  • 10. main( ) { One More Try int a = 10, b = 20, c = 30 ; int s, p ; s = sumprod ( a, b, c ) ; p = sumprod ( a, b, c ) ; printf ( ”%d%d”, s, p ) ; } sumprod ( int x, int y, int z ) { ss = x + y + z ; pp = x * y * z ; return ( ss ) ; return ( pp ) ; } int ss, pp ; 60 60 Redundant
  • 11. main( ) { The Only Way Out int a = 10, b = 20, c = 30 ; int s, p ; s = sumprod ( a, b, c ) ; p = sumprod ( a, b, c ) ; printf ( ”%d%d”, s, p ) ; } , 1 , 2 sumprod ( int x, int y, int z, ) { int ss, pp ; ss = x + y + z ; pp = x * y * z ; } int code if ( code == 1 ) return ( ss ) ; else return ( pp ) ; Sum, Product, Average, Variance Standard Deviation
  • 12. A Better Way sumprod ( int x, int y, int z, int code ) { int ss, pp ; ss = x + y + z ; pp = x * y * z ; } if ( code == 1 ) return ( ss ) ; else return ( pp ) ; code == 1 ? return ( x + y + z ) : return ( x * y * z ) ; return ( code == 1 ? x + y + z : x * y * z ) ;
  • 13. ANSI V/s K R calsum ( int x, int y, int z ) { .. } calsum ( int x, int y, int z ) { .. } calsum ( x, y, z ) int x, y, z ; { .. } calsum ( x, y, z ) int x, y, z ; { .. } ANSI Kernighan Ritchie
  • 14. main( ) { int y ; printf ( ”Enter year” ) ; scanf ( ”%d”, y ) ; romanize ( y ) ; } romanize ( int yy ) { int n, i ; n = yy / 1000 ; for ( i = 1 ; i = n ; i ++ ) printf ( ”m” ) ; Decimal Roman 1000 m 500 d 100 c 50 l 10 x 5 v 1 i } Roman Equivalent 1998 m d c c c c l x x x x i i i 1998 v
  • 15. A More General Call main( ) { int y ; printf ( ”Enter year” ) ; scanf ( ”%d”, y ) ; , 1000 , ’m’ y romanize = romanise ( y ( y, 1000, ’) m’ ; ) ; } romanize ( int yy , int j , char ch ) { int n, i ; n = yy / j ; for ( i = 1 ; i = n ; i ++ ) printf ( ) ; } ”%c”, ch return ( yy % j ) ;
  • 16. main( ) { ... 1998 md c c c c lx xx x v i ii , ’m’ y = romanise ( y, 1000 ) ; y = romanise ( y, 500, ’d’ ) ; y = romanise ( y, 100, ’c’ ) ; y = romanise ( y, 50, ’l’ ) ; y = romanise ( y, 10, ’x’ ) ; y = romanise ( y, 5, ’v’ ) ; romanise ( y, 1, ’i’ ) ; } romanize ( int yy ) { } , int j, char ch int n, i ; n = yy / j ; for ( i = 1 ; i = n ; i ++ ) printf ( ”%c”, ch ) ; return ( yy % j ) ; Works
  • 17. Advanced Features of Functions Returning a non-integer value Call by value / Call by reference Recursion
  • 18. Returning a Non-Integer Value main( ) { a = square ( 2.0 ) ; b = square ( 2.5 ) ; c = square ( 1.5 ) ; printf ( ” %f %f %f ”, a, b, c, ) ; square ( 2.0 ) ; } square ( ) float x { float y ; y = x * x ; printf ( ” %f ”, y ) ; return ( y ) ; } Function Prototype 4.0 6.0 2.0 float a, b, c ; float square ( float ) ; 4.0 6.25 2.25 float square ( float x )