Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Understanding Functions, Parameters, and Argument Passing in C Language, Study Guides, Projects, Research of C programming

The concept of functions, formal and actual parameters, and argument passing in c language. It covers the declaration of functions, the difference between formal and actual parameters, and the use of a parameter list. Examples are provided to illustrate the concepts.

Typology: Study Guides, Projects, Research

2021/2022

Uploaded on 09/27/2022

gerrard
gerrard 🇮🇹

3.9

(7)

213 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Programming and Problem Solving through C Language
O Level / A Level
Chapter - 6 : Functions
Function Arguments
If a function is to use arguments, it must declare variables that accept the values of the
arguments. These variables are called the formal parameters of the function. Formal parameters
behave like other local variables inside the function and are created upon entry into the function and
destroyed upon exit.
Parameter
A parameter is a special kind of variable, used in a function to refer to one of the pieces of
data provided as input to the function to utilse.
These pieces of data are called arguments.
Parameters are Simply Variables.
Formal Parameter
Parameter Written in Function Definition is Called “Formal Parameter.
Formal parameters are always variables, while actual parameters do not have to be
variables.
Actual Parameter
Parameter Written in Function Call is Called “Actual Parameter”.
One can use numbers, expressions, or even function calls as actual parameters.
Example
void display(int para1)
{
printf( “ Number %d “ , para1);
}
void main()
{ int num1;
display(num1);
}
In above, para1 is called the Formal Parameter
num1 is called the Actual Parameter.
pf3

Partial preview of the text

Download Understanding Functions, Parameters, and Argument Passing in C Language and more Study Guides, Projects, Research C programming in PDF only on Docsity!

Programming and Problem Solving through C Language

O Level / A Level

Chapter - 6 : Functions

Function Arguments

If a function is to use arguments, it must declare variables that accept the values of the arguments. These variables are called the formal parameters of the function. Formal parameters behave like other local variables inside the function and are created upon entry into the function and destroyed upon exit.

Parameter

 A parameter is a special kind of variable, used in a function to refer to one of the pieces of data provided as input to the function to utilse.  These pieces of data are called arguments.  Parameters are Simply Variables.

Formal Parameter

 Parameter Written in Function Definition is Called “Formal Parameter.  Formal parameters are always variables, while actual parameters do not have to be variables.

Actual Parameter

 Parameter Written in Function Call is Called “Actual Parameter”.  One can use numbers, expressions, or even function calls as actual parameters. Example void display(int para1) { printf( “ Number %d “ , para1); } void main() { int num1; display(num1); } In above, para1 is called the Formal Parameter num1 is called the Actual Parameter.

Parameter list

 A function is declared in the following manner: returntype functionname (parameterlist,...) { body... }  Returntype is the variable type that the function returns.  This cannot be an array type or a function type.  If not given, then int is assumed.  Functionname is the name of the function.  Parameterlist is the list of Formal Arguments Variable.  Given below are few examples: o int func1(int a, int b) /* two argument – int , int / o float func2(int a, float b) / two argument – int , float / o void func3( ) / No argument. */

The Function Return Type

 The function return type specifies the data type that the function returns to the calling program.  The return type can be any of C′s data types: char, int , long , float , or double.  One can also define a function that doesn′t return a value by using a return type of void.  Given below are few examples: o int func1(...) /* Returns a type int. / o float func2(...) / Returns a type float. / o void func3(...) / No Returns. */