PROGRAMMING IN C
Unit 2
Lecture-3
Unit-2 Syllabus
Control structures: Decision statements; if and switch statement; Loop
control statements: while, for and do while loops, jump statements,
break, continue, goto statements.
Arrays: Concepts, One dimensional array, declaration and initialization
of one dimensional arrays, two dimensional arrays, initialization and
accessing, multi dimensional arrays.
Functions: User defined and built-in Functions, storage classes,
Parameter passing in functions, call by value, Passing arrays to functions:
idea of call by reference, Recursion.
Strings: Arrays of characters, variable length character strings, inputting
character strings, character library functions, string handling functions.
In this Lecture
User defined and built-in Functions
Parameter passing in functions
Call by value , Call by reference
Passing arrays to functions
Functions
Derived Data type
Enclosed with {}
Perform Specific Task
Provides Code reusibility
Understanding Function in C
Declaration
Defination
Calling
Declaration
of Function
return_type
name_of_the_function
(parameter_1,
parameter_2);
Defining a
Function
return_type function_name
(para1_type para1_name,
para2_type para2_name)
{
// body of the function
}
Calling a
Function
Write a program to give sum
of two numbers using
function
Built-in Vs User Defined Functions
Built-in Function User-Defined Function
Also known as Library Function
Already existed in the compiler Created by the user
package
Any name can be given by the user
Has a fixed pre-defined name
Must be declared and defined
Directly useable without being before being used
defined
E.g) pow(), sqrt(), strcmp(), strcpy()
etc.
Actual and
Formal
Parameters
Call By Value
Output
Call By Reference
Output
Call By Value VS Call By Reference
Call By Value Call By Reference
There are two copies of Both the actual and formal
parameters stored in different parameters refer to the same
memory [Link] is the locations.
original copy and the other is Any changes made inside the
the function copy.
function are actually reflected
Any changes made inside in the actual parameters of the
functions are not reflected in caller.
the actual parameters of the
caller.
Passing
Arrays to
Function
Write a program to get the
sum of all the elements of
an array using function
Sum of all
elements of
an Array
Write a program to
get the maximum
Self Practice number from the
array using Function
Self Practice
Thank You