

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
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
1 / 3
This page cannot be seen from the preview
Don't miss anything!
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.
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.
Parameter Written in Function Definition is Called “Formal Parameter. Formal parameters are always variables, while actual parameters do not have to be variables.
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.
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 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. */