SlideShare a Scribd company logo
1 of 39
D.E.I. TECHNICAL COLLEGE
COURSE TITLE: Software Development-VI
SLIDE-1
COURSE CODE: VIT351
CLASS: DIPLOMA IN INFORMATION TECHNOLOGY VOCATIONAL (1ST YEAR)
SESSION: 2019-20
TOPICS COVER
 C STANDARD LIBRARIES
 FUNCTIONS IN C
 RECURSION
 QUIZ SET
C Standard Library
C is the programming language which near to
human as well as machine.
It is popularly known as “Middle level Programming
Language”.
C is a powerful, flexible language and has got a
widespread use with a rich standard library of
functions.
C standard library is the standard collection of header
files used to perform certain common operations.
GO TO TOPICS
The C standard library provides macros, type definitions
and functions for various tasks such as:
 Mathematical Computations
 String handling
 Input/output Processing
 Memory Management
 Other operating system services
What is header files?
Both the user and the system header files are
included using pre-processing directive #include
Include Syntax has following forms:
#include <file>
It is used for system header files. It searches for ‘file’ in a
standard list of system directories.
#include “file”
It is used for header file of one’s own program. It searches for
a file named ‘file’ in the directory having the current file.
Continue….
 The most commonly used header file in C are:
stdio.h
string.h
stdlib.h
math.h
ctype.h
alloc.h
GO TO TOPICS
Functions
A function contains set of instructions enclosed by ‘{ }’
which performs specific operation.
 Function is a piece of code to perform a particular task
 Function is a block of code which performs usually a unit task
 It has some name for identification
 Action statements in C language can only reside in some function
block.
Benefits
 They make program handling easier.
 They reduce the program size.
 They make program more readable and understandable.
 They can be repeated in the same program.
Advantages of Functions
 It avoids re-writing of same code over and over
 Achieve modularization
 Easy to read
 Easy to debug
 Easy to modify
 Better memory utilization
o Function consumes memory on its call
o Function releases memory after its execution
Function
Built-in Functions/ Library Functions
The functions that are provided by
C library. They are the part of the
compiler packages.
Ex- pow(), sqrt() etc.,
User-defined Functions
The functions that are created by
the programmers themselves to
carry out an operation.
Aspect
Function Declaration
or Prototype
Function Call
Function Definition
Functions declaration & definition
 Function Declaration
Syntax:
return_type function_name (data_type arg1, data_type arg2)
int add(int x, int y); //function declaration
 Function Definition
Syntax:
int add(int, int); //function declaration
//function definition
return_type function_name(parameters)
{
Function body
}
Continue…
 Function Header: function header is same as function declaration
without the semicolon. Function header contains function name,
parameter & return type.
 Return Type: Return type is the data type of the value which will be
returned by the function. The function may or may not return a value. If
it does then the data type of the retuning value should be specified,
otherwise the return type needs to be void.
 Function Name: This is the name of the function using which we can
call the function when & where needed.
 Parameters: The parameters are the input values which will be passed
to the function. It tells about the data types of the arguments, their
order and the number of arguments that will be passed to the
function. The parameters are optional. You can also have functions
without parameters.
 Function Body: The function body is the set of statement which
performs a specific task. It defines what the function does.
Example:
#include <stdio.h>
int add(int, int); //function declaration
// function definition
int add(int x, int y) //function header
{
// function body
int sum = x+y;
return(sum);
}
// Main Function
int main()
{
int sum = add(23, 31);
printf("%d", sum);
return 0;
}
Ways to define functions
There are 4 ways to define the functions:
1. No arguments passed and no return Value
2. No arguments passed but a return value
3. Argument passed but no return value
4. Argument passed and a return value
1.No arguments passed and no return Value
Example:
#include <stdio.h>
void add();
void add()
{
int x = 20;
int y = 30;
int sum = x+y;
printf("sum %d", sum);
}
int main()
{
add();
return 0;
}
Syntax:
function declaration:
void function();
function call: function();
function definition:
void function()
{
statements;
}
2. No arguments passed but a return value
Example:
#include <stdio.h>
int add();
int add()
{
int x = 20;
int y = 30;
int sum = x+y;
return(sum);
}
int main()
{
int sum;
sum = add();
printf("sum %d", sum);
return 0;
}
Syntax:
function declaration:
int function ( );
function call: function ( );
function definition:
int function( )
{
statements;
return a;
3. Argument passed but no return value
Example:
#include <stdio.h>
void add(int, int);
void add(int x, int y)
{
int sum = x+y;
return(sum);
}
int main()
{
add(23, 31);
return 0;
}
Syntax:
function declaration:
void function ( int );
function call: function( a );
function definition:
void function( int a )
{
statements;
}
4. Argument passed and a return value
Example:
#include <stdio.h>
int add(int, int);
int add(int x, int y)
{
int sum = x+y;
return(sum);
}
int main()
{
int sum = add(23, 31);
printf("%d", sum);
return 0;
}
Syntax:
function declaration:
int function ( int );
function call: function ( a );
function definition:
int function( int a )
{
statements;
return a;
}
Method of Calling
1. Call by Value
Calling a function by value means, we pass the values of the arguments which are stored or copied
into the formal parameters of the function. Hence, the original values are unchanged only the
parameters inside the function changes.
2. Call by Reference
In call by reference we pass the address(reference) of a variable as argument to any function. When
we pass the address of any variable as argument, then the function will have access to our variable,
as it now knows where it is stored and hence can easily update its value.
 Actual Parameter: Those parameters which are passed to functions while calling them is are known
as actual parameter.
For example, 23 & 31 in the above example are the actual parameters.
 Formal Parameter: Those parameters which are received by the functions are known as formal
parameters.
For example, x & y in the above example are the formal parameters.
Call by value
#include <stdio.h>
void Call_By_Value(int num1)
{
num1=42;
printf("nInside Function, Number is %d", num1);
}
int main()
{
int num;
num=24;
printf("nBefore Function, Number is %d", num);
Call_By_Value(num);
printf("nAfter Function, Number is %dn", num);
return 0;
}
Parameters Call by value
Definition
While calling a function, when you pass values by copying variables, it is known as "Call By
Values."
Arguments In this method, a copy of the variable is passed.
Effect Changes made in a copy of variable never modify the value of variable outside the function.
Alteration of value Does not allow you to make any changes in the actual variables.
Passing of variable Values of variables are passed using a straightforward method.
Value modification Original value not modified.
Memory Location Actual and formal arguments will be created in different memory location
Safety Actual arguments remain safe as they cannot be modified accidentally.
Default Default in many programming languages like C++.PHP. Visual Basic NET, and C#.
Call by Reference
#include <stdio.h>
// function definition
void Call_By_Reference(int *num1)
{
*num1=42;
printf("nInside Function, Number is %d", *num1);
}
// Main Function
int main()
{
int num;
num=24;
printf("nBefore Function, Number is %d", num);
Call_By_Reference(&num);
printf("nAfter Function, Number is %dn", num);
return 0;
}
Parameters Call by reference
Definition
While calling a function, in programming language instead of copying the values of
variables, the address of the variables is used it is known as "Call By References.
Arguments In this method, a variable itself is passed.
Effect Change in the variable also affects the value of the variable outside the function.
Alteration of value Allows you to make changes in the values of variables by using function calls.
Passing of variable Pointer variables are required to store the address of variables.
Value modification The original value is modified.
Memory Location Actual and formal arguments will be created in the same memory location
Safety
Actual arguments are not Safe. They can be accidentally modified, so you need to
handle arguments operations carefully.
Default It is supported by most programming languages like JAVA, but not as default.
What is Recursion?
Recursion is a special way of nesting functions, where a function calls itself inside it. We must
have certain conditions in the function to break out of the recursion, otherwise recursion will
occur infinite times.
function1()
{
// function1 body
function1();
// function1 body
}
Not every problem can be solved using recursion
If a problem can be solved using recursion, then it must have an iterative solution too.
Recursion is easy to implement as compare to iterative solution
Recursion takes more memory
Simple code which is easy to understand is always considered as a good code, therefore
recursive functions are used.
GO TO TOPICS
Continue..
There are several types of recursion
 Linear Recursion
A linear recursive function is a function that only makes a single call to itself each time the function
runs (as opposed to one that would call itself multiple times during its execution). The factorial
function is a good example of linear recursion.
 Tail Recursion
A function call is said to be tail recursive if there is nothing to do after the function returns except
return its value
 Binary Recursion
Some recursive functions don't just have one call to them-self, they have two (or more). Functions
with two recursive calls are referred to as binary recursive functions.
 Exponential Recursion
An exponential recursive function is one that, if you were to draw out a representation of all the
function calls, would have an exponential number of calls in relation to the size of the data set
(exponential meaning if there were n elements, there would be O(a n) function calls where a is a
positive number).
 Indirect recursion
A recursive function doesn't necessarily need to call itself. Some recursive functions work in pairs.
Function A calls B and B calls A.
Example1: Recursion
#include<stdio.h>
int factorial(int x);
//declaring the function
void main()
{
int a, b;
printf("Enter a number...");
scanf("%d", &a);
b = factorial(a);
//calling the function named factorial
printf("%d", b);
}
int factorial(int x)
//defining the function
{
int r = 1;
if(x == 1)
return 1;
else
r = x*factorial(x-1);
//recursion, since the function calls itself
return r;
}
Example2: Recursion
#include <stdio.h>
int sum(int n);
int main() {
int number, result;
printf("Enter a positive integer: ");
scanf("%d", &number);
result = sum(number);
printf("sum = %d", result);
return 0;
}
int sum(int n) {
if (n != 0)
// sum() function calls itself
return n + sum(n-1);
else
return n;
}
How it works?
Advantages and Disadvantages of Recursion
 Recursion makes program elegant. However, if performance is vital,
use loops instead as recursion is usually much slower.
 That being said, recursion is an important concept. It is frequently
used in data structure and algorithms.
For example, it is common to use recursion in problems such as tree
traversal.
Quiz Set: 1
 Standard Libraries
 Functions
GO TO TOPICS
2. What does a C header file contain?
A. It refers to the collection of Header Files
B. It is a collection of classes.
C. It is a collection of standard functions.
D. It refers to special variables and objects.
1. What is C standard Library?
A. It contains the various classes.
B. It contains various special objects, special variables
and function prototypes.
C. The header file contains the function codes.
D. It is a blank file containing nothing.
4. Which header file used to perform
mathematical operation.
A. We copy the file in the program.
B. We keep the header file in the same folder where program exists.
C. We use the directive ‘include’ so that the content copied into the
program.
D. We copy the content of the header file into the program.
3. What do you do when you wish to use header file?
A. <ctype.h>
B. <math.h>
C. <alloc.h>
D. <String.h>
6. Which header file is used to allocate memory
dynamically.
A. <math.h>
B. <stdio.h>
C. <alloc.h>
D. <ctype.h>
5. Which header file support scanf() function?
A. <math.h>
B. <stdio.h>
C. <alloc.h>
D. <ctype.h>
A. To do special I/O Functions.
B. To check the type of character being used.
C. To find a character in a string.
D. To declare a variable for storing character.
7. Why do we use ctype.h?
8. What is the disadvantage of function?
A. Function allows sharing of codes.
B. Function allows minimization of size of the code.
C. Functions can not be flexibly used with different types of
inputs.
D. Functions help where are repeating of code.
9. What does a function prototype not contain?
A. Function Codes
B. Function Parameters
C. Return Type
D. Function Name
10. What make a function definition?
A. Name and return types
B. Name, return type and parameters
C. Function prototype and function body
D. The codes make the definition of function
11. What is a formal parameter?
A. A formal parameters are a part of function prototype.
B. A formal parameters are the arguments passed when the
function is invoked.
C. The formal parameters are the values passed as arguments
D. None of the above are true
12. What are actual parameters of a function?
A. Actual parameters are defined with the function prototypes
B. Actual parameters are the argument passed when the function is
invoked.
C. Actual parameters are formal parameters.
D. Actual parameters are part of a function definition.
Continue……
In Slide 2

More Related Content

What's hot (20)

user defined function
user defined functionuser defined function
user defined function
 
predefined and user defined functions
predefined and user defined functionspredefined and user defined functions
predefined and user defined functions
 
Python functions
Python functionsPython functions
Python functions
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Functions assignment
Functions assignmentFunctions assignment
Functions assignment
 
Recursive Function
Recursive FunctionRecursive Function
Recursive Function
 
Function & Recursion
Function & RecursionFunction & Recursion
Function & Recursion
 
Unit iv functions
Unit  iv functionsUnit  iv functions
Unit iv functions
 
Python algorithm
Python algorithmPython algorithm
Python algorithm
 
FUNCTION CPU
FUNCTION CPUFUNCTION CPU
FUNCTION CPU
 
Functions in python
Functions in pythonFunctions in python
Functions in python
 
3. functions modules_programs (1)
3. functions modules_programs (1)3. functions modules_programs (1)
3. functions modules_programs (1)
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
 
Chapter 11 Function
Chapter 11 FunctionChapter 11 Function
Chapter 11 Function
 
Python recursion
Python recursionPython recursion
Python recursion
 
Lecture21 categoriesof userdefinedfunctions.ppt
Lecture21 categoriesof userdefinedfunctions.pptLecture21 categoriesof userdefinedfunctions.ppt
Lecture21 categoriesof userdefinedfunctions.ppt
 
User_Defined_Functions_ppt_slideshare.
User_Defined_Functions_ppt_slideshare.User_Defined_Functions_ppt_slideshare.
User_Defined_Functions_ppt_slideshare.
 
Functions
FunctionsFunctions
Functions
 
Functions in python
Functions in python Functions in python
Functions in python
 
Ch9 Functions
Ch9 FunctionsCh9 Functions
Ch9 Functions
 

Similar to VIT351 Software Development VI Unit1

Similar to VIT351 Software Development VI Unit1 (20)

Functions
Functions Functions
Functions
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
 
Functionincprogram
FunctionincprogramFunctionincprogram
Functionincprogram
 
Ch4 functions
Ch4 functionsCh4 functions
Ch4 functions
 
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptxUnit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
 
Funtions of c programming. the functions of c helps to clarify all the tops
Funtions of c programming. the functions of c helps to clarify all the topsFuntions of c programming. the functions of c helps to clarify all the tops
Funtions of c programming. the functions of c helps to clarify all the tops
 
C function
C functionC function
C function
 
Lecture 11 - Functions
Lecture 11 - FunctionsLecture 11 - Functions
Lecture 11 - Functions
 
Chapter_1.__Functions_in_C++[1].pdf
Chapter_1.__Functions_in_C++[1].pdfChapter_1.__Functions_in_C++[1].pdf
Chapter_1.__Functions_in_C++[1].pdf
 
Chapter 1. Functions in C++.pdf
Chapter 1.  Functions in C++.pdfChapter 1.  Functions in C++.pdf
Chapter 1. Functions in C++.pdf
 
Unit 3 (1)
Unit 3 (1)Unit 3 (1)
Unit 3 (1)
 
arrays.ppt
arrays.pptarrays.ppt
arrays.ppt
 
Functions
FunctionsFunctions
Functions
 
Functions in c
Functions in cFunctions in c
Functions in c
 
4. function
4. function4. function
4. function
 
Functions in c
Functions in cFunctions in c
Functions in c
 
unit_2.pptx
unit_2.pptxunit_2.pptx
unit_2.pptx
 
unit_2 (1).pptx
unit_2 (1).pptxunit_2 (1).pptx
unit_2 (1).pptx
 
04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx
 
Module 3-Functions
Module 3-FunctionsModule 3-Functions
Module 3-Functions
 

More from YOGESH SINGH

VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5YOGESH SINGH
 
VIT351 Software Development VI Unit4
VIT351 Software Development VI Unit4VIT351 Software Development VI Unit4
VIT351 Software Development VI Unit4YOGESH SINGH
 
VIT351 Software Development VI Unit3
VIT351 Software Development VI Unit3VIT351 Software Development VI Unit3
VIT351 Software Development VI Unit3YOGESH SINGH
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2YOGESH SINGH
 
DEE 431 Introduction to MySql Slide 6
DEE 431 Introduction to MySql Slide 6DEE 431 Introduction to MySql Slide 6
DEE 431 Introduction to MySql Slide 6YOGESH SINGH
 
DEE 431 Introduction to Mysql Slide 3
DEE 431 Introduction to Mysql Slide 3DEE 431 Introduction to Mysql Slide 3
DEE 431 Introduction to Mysql Slide 3YOGESH SINGH
 
DEE 431 Database keys and Normalisation Slide 2
DEE 431 Database keys and Normalisation Slide 2DEE 431 Database keys and Normalisation Slide 2
DEE 431 Database keys and Normalisation Slide 2YOGESH SINGH
 
DEE 431 Introduction to DBMS Slide 1
DEE 431 Introduction to DBMS Slide 1DEE 431 Introduction to DBMS Slide 1
DEE 431 Introduction to DBMS Slide 1YOGESH SINGH
 

More from YOGESH SINGH (8)

VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5
 
VIT351 Software Development VI Unit4
VIT351 Software Development VI Unit4VIT351 Software Development VI Unit4
VIT351 Software Development VI Unit4
 
VIT351 Software Development VI Unit3
VIT351 Software Development VI Unit3VIT351 Software Development VI Unit3
VIT351 Software Development VI Unit3
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
 
DEE 431 Introduction to MySql Slide 6
DEE 431 Introduction to MySql Slide 6DEE 431 Introduction to MySql Slide 6
DEE 431 Introduction to MySql Slide 6
 
DEE 431 Introduction to Mysql Slide 3
DEE 431 Introduction to Mysql Slide 3DEE 431 Introduction to Mysql Slide 3
DEE 431 Introduction to Mysql Slide 3
 
DEE 431 Database keys and Normalisation Slide 2
DEE 431 Database keys and Normalisation Slide 2DEE 431 Database keys and Normalisation Slide 2
DEE 431 Database keys and Normalisation Slide 2
 
DEE 431 Introduction to DBMS Slide 1
DEE 431 Introduction to DBMS Slide 1DEE 431 Introduction to DBMS Slide 1
DEE 431 Introduction to DBMS Slide 1
 

Recently uploaded

A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxmaisarahman1
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdfKamal Acharya
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaOmar Fathy
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"mphochane1998
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARKOUSTAV SARKAR
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsvanyagupta248
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network DevicesChandrakantDivate1
 
Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfsumitt6_25730773
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksMagic Marks
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Call Girls Mumbai
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...HenryBriggs2
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...vershagrag
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiessarkmank1
 
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptxrouholahahmadi9876
 

Recently uploaded (20)

A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdf
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic Marks
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
 

VIT351 Software Development VI Unit1

  • 1. D.E.I. TECHNICAL COLLEGE COURSE TITLE: Software Development-VI SLIDE-1 COURSE CODE: VIT351 CLASS: DIPLOMA IN INFORMATION TECHNOLOGY VOCATIONAL (1ST YEAR) SESSION: 2019-20
  • 2. TOPICS COVER  C STANDARD LIBRARIES  FUNCTIONS IN C  RECURSION  QUIZ SET
  • 3. C Standard Library C is the programming language which near to human as well as machine. It is popularly known as “Middle level Programming Language”. C is a powerful, flexible language and has got a widespread use with a rich standard library of functions. C standard library is the standard collection of header files used to perform certain common operations. GO TO TOPICS
  • 4. The C standard library provides macros, type definitions and functions for various tasks such as:  Mathematical Computations  String handling  Input/output Processing  Memory Management  Other operating system services
  • 5. What is header files?
  • 6. Both the user and the system header files are included using pre-processing directive #include Include Syntax has following forms: #include <file> It is used for system header files. It searches for ‘file’ in a standard list of system directories. #include “file” It is used for header file of one’s own program. It searches for a file named ‘file’ in the directory having the current file.
  • 7. Continue….  The most commonly used header file in C are: stdio.h string.h stdlib.h math.h ctype.h alloc.h
  • 9. Functions A function contains set of instructions enclosed by ‘{ }’ which performs specific operation.  Function is a piece of code to perform a particular task  Function is a block of code which performs usually a unit task  It has some name for identification  Action statements in C language can only reside in some function block. Benefits  They make program handling easier.  They reduce the program size.  They make program more readable and understandable.  They can be repeated in the same program.
  • 10. Advantages of Functions  It avoids re-writing of same code over and over  Achieve modularization  Easy to read  Easy to debug  Easy to modify  Better memory utilization o Function consumes memory on its call o Function releases memory after its execution
  • 11. Function Built-in Functions/ Library Functions The functions that are provided by C library. They are the part of the compiler packages. Ex- pow(), sqrt() etc., User-defined Functions The functions that are created by the programmers themselves to carry out an operation.
  • 13. Functions declaration & definition  Function Declaration Syntax: return_type function_name (data_type arg1, data_type arg2) int add(int x, int y); //function declaration  Function Definition Syntax: int add(int, int); //function declaration //function definition return_type function_name(parameters) { Function body }
  • 14. Continue…  Function Header: function header is same as function declaration without the semicolon. Function header contains function name, parameter & return type.  Return Type: Return type is the data type of the value which will be returned by the function. The function may or may not return a value. If it does then the data type of the retuning value should be specified, otherwise the return type needs to be void.  Function Name: This is the name of the function using which we can call the function when & where needed.  Parameters: The parameters are the input values which will be passed to the function. It tells about the data types of the arguments, their order and the number of arguments that will be passed to the function. The parameters are optional. You can also have functions without parameters.  Function Body: The function body is the set of statement which performs a specific task. It defines what the function does.
  • 15. Example: #include <stdio.h> int add(int, int); //function declaration // function definition int add(int x, int y) //function header { // function body int sum = x+y; return(sum); } // Main Function int main() { int sum = add(23, 31); printf("%d", sum); return 0; }
  • 16. Ways to define functions There are 4 ways to define the functions: 1. No arguments passed and no return Value 2. No arguments passed but a return value 3. Argument passed but no return value 4. Argument passed and a return value
  • 17. 1.No arguments passed and no return Value Example: #include <stdio.h> void add(); void add() { int x = 20; int y = 30; int sum = x+y; printf("sum %d", sum); } int main() { add(); return 0; } Syntax: function declaration: void function(); function call: function(); function definition: void function() { statements; }
  • 18. 2. No arguments passed but a return value Example: #include <stdio.h> int add(); int add() { int x = 20; int y = 30; int sum = x+y; return(sum); } int main() { int sum; sum = add(); printf("sum %d", sum); return 0; } Syntax: function declaration: int function ( ); function call: function ( ); function definition: int function( ) { statements; return a;
  • 19. 3. Argument passed but no return value Example: #include <stdio.h> void add(int, int); void add(int x, int y) { int sum = x+y; return(sum); } int main() { add(23, 31); return 0; } Syntax: function declaration: void function ( int ); function call: function( a ); function definition: void function( int a ) { statements; }
  • 20. 4. Argument passed and a return value Example: #include <stdio.h> int add(int, int); int add(int x, int y) { int sum = x+y; return(sum); } int main() { int sum = add(23, 31); printf("%d", sum); return 0; } Syntax: function declaration: int function ( int ); function call: function ( a ); function definition: int function( int a ) { statements; return a; }
  • 21. Method of Calling 1. Call by Value Calling a function by value means, we pass the values of the arguments which are stored or copied into the formal parameters of the function. Hence, the original values are unchanged only the parameters inside the function changes. 2. Call by Reference In call by reference we pass the address(reference) of a variable as argument to any function. When we pass the address of any variable as argument, then the function will have access to our variable, as it now knows where it is stored and hence can easily update its value.  Actual Parameter: Those parameters which are passed to functions while calling them is are known as actual parameter. For example, 23 & 31 in the above example are the actual parameters.  Formal Parameter: Those parameters which are received by the functions are known as formal parameters. For example, x & y in the above example are the formal parameters.
  • 22. Call by value #include <stdio.h> void Call_By_Value(int num1) { num1=42; printf("nInside Function, Number is %d", num1); } int main() { int num; num=24; printf("nBefore Function, Number is %d", num); Call_By_Value(num); printf("nAfter Function, Number is %dn", num); return 0; }
  • 23. Parameters Call by value Definition While calling a function, when you pass values by copying variables, it is known as "Call By Values." Arguments In this method, a copy of the variable is passed. Effect Changes made in a copy of variable never modify the value of variable outside the function. Alteration of value Does not allow you to make any changes in the actual variables. Passing of variable Values of variables are passed using a straightforward method. Value modification Original value not modified. Memory Location Actual and formal arguments will be created in different memory location Safety Actual arguments remain safe as they cannot be modified accidentally. Default Default in many programming languages like C++.PHP. Visual Basic NET, and C#.
  • 24. Call by Reference #include <stdio.h> // function definition void Call_By_Reference(int *num1) { *num1=42; printf("nInside Function, Number is %d", *num1); } // Main Function int main() { int num; num=24; printf("nBefore Function, Number is %d", num); Call_By_Reference(&num); printf("nAfter Function, Number is %dn", num); return 0; }
  • 25. Parameters Call by reference Definition While calling a function, in programming language instead of copying the values of variables, the address of the variables is used it is known as "Call By References. Arguments In this method, a variable itself is passed. Effect Change in the variable also affects the value of the variable outside the function. Alteration of value Allows you to make changes in the values of variables by using function calls. Passing of variable Pointer variables are required to store the address of variables. Value modification The original value is modified. Memory Location Actual and formal arguments will be created in the same memory location Safety Actual arguments are not Safe. They can be accidentally modified, so you need to handle arguments operations carefully. Default It is supported by most programming languages like JAVA, but not as default.
  • 26. What is Recursion? Recursion is a special way of nesting functions, where a function calls itself inside it. We must have certain conditions in the function to break out of the recursion, otherwise recursion will occur infinite times. function1() { // function1 body function1(); // function1 body } Not every problem can be solved using recursion If a problem can be solved using recursion, then it must have an iterative solution too. Recursion is easy to implement as compare to iterative solution Recursion takes more memory Simple code which is easy to understand is always considered as a good code, therefore recursive functions are used. GO TO TOPICS
  • 27. Continue.. There are several types of recursion  Linear Recursion A linear recursive function is a function that only makes a single call to itself each time the function runs (as opposed to one that would call itself multiple times during its execution). The factorial function is a good example of linear recursion.  Tail Recursion A function call is said to be tail recursive if there is nothing to do after the function returns except return its value  Binary Recursion Some recursive functions don't just have one call to them-self, they have two (or more). Functions with two recursive calls are referred to as binary recursive functions.  Exponential Recursion An exponential recursive function is one that, if you were to draw out a representation of all the function calls, would have an exponential number of calls in relation to the size of the data set (exponential meaning if there were n elements, there would be O(a n) function calls where a is a positive number).  Indirect recursion A recursive function doesn't necessarily need to call itself. Some recursive functions work in pairs. Function A calls B and B calls A.
  • 28. Example1: Recursion #include<stdio.h> int factorial(int x); //declaring the function void main() { int a, b; printf("Enter a number..."); scanf("%d", &a); b = factorial(a); //calling the function named factorial printf("%d", b); } int factorial(int x) //defining the function { int r = 1; if(x == 1) return 1; else r = x*factorial(x-1); //recursion, since the function calls itself return r; }
  • 29. Example2: Recursion #include <stdio.h> int sum(int n); int main() { int number, result; printf("Enter a positive integer: "); scanf("%d", &number); result = sum(number); printf("sum = %d", result); return 0; } int sum(int n) { if (n != 0) // sum() function calls itself return n + sum(n-1); else return n; }
  • 31. Advantages and Disadvantages of Recursion  Recursion makes program elegant. However, if performance is vital, use loops instead as recursion is usually much slower.  That being said, recursion is an important concept. It is frequently used in data structure and algorithms. For example, it is common to use recursion in problems such as tree traversal.
  • 32. Quiz Set: 1  Standard Libraries  Functions GO TO TOPICS
  • 33. 2. What does a C header file contain? A. It refers to the collection of Header Files B. It is a collection of classes. C. It is a collection of standard functions. D. It refers to special variables and objects. 1. What is C standard Library? A. It contains the various classes. B. It contains various special objects, special variables and function prototypes. C. The header file contains the function codes. D. It is a blank file containing nothing.
  • 34. 4. Which header file used to perform mathematical operation. A. We copy the file in the program. B. We keep the header file in the same folder where program exists. C. We use the directive ‘include’ so that the content copied into the program. D. We copy the content of the header file into the program. 3. What do you do when you wish to use header file? A. <ctype.h> B. <math.h> C. <alloc.h> D. <String.h>
  • 35. 6. Which header file is used to allocate memory dynamically. A. <math.h> B. <stdio.h> C. <alloc.h> D. <ctype.h> 5. Which header file support scanf() function? A. <math.h> B. <stdio.h> C. <alloc.h> D. <ctype.h>
  • 36. A. To do special I/O Functions. B. To check the type of character being used. C. To find a character in a string. D. To declare a variable for storing character. 7. Why do we use ctype.h? 8. What is the disadvantage of function? A. Function allows sharing of codes. B. Function allows minimization of size of the code. C. Functions can not be flexibly used with different types of inputs. D. Functions help where are repeating of code.
  • 37. 9. What does a function prototype not contain? A. Function Codes B. Function Parameters C. Return Type D. Function Name 10. What make a function definition? A. Name and return types B. Name, return type and parameters C. Function prototype and function body D. The codes make the definition of function
  • 38. 11. What is a formal parameter? A. A formal parameters are a part of function prototype. B. A formal parameters are the arguments passed when the function is invoked. C. The formal parameters are the values passed as arguments D. None of the above are true 12. What are actual parameters of a function? A. Actual parameters are defined with the function prototypes B. Actual parameters are the argument passed when the function is invoked. C. Actual parameters are formal parameters. D. Actual parameters are part of a function definition.