C Language

Function Call

In C Language by Baqir AliLeave a Comment

A function can be accessed, called, or invoked by specifying its name, followed by a list of arguments enclosed in parentheses and separated by commas. If the function call does not require any arguments then an empty pair of parentheses must follow the name of the function. The function call may be part of a simple expression, such as an assignment statement, or it may be one of the operands within a more complex expression.

The arguments appearing in a function call may be expressed as constants, single variables, or more complex expressions. However, both the number and the types of the arguments must match those in the function definition.

Function call general form

f_name(exp1, exp2, …, expN)

Where exp is an expression that can be a single variable or constant.   (exp1, exp2, …, expn) is the argument list.

A function returning a value is called:

 r_value = f_name(exp1, exp2, …, expn); 

A function which doesn’t return a value can be called:

f_name(exp1, exp2, …, expn); 

Example 1:

int add(int a, int b)
   int sum;
   sum = a + b;
   return sum;
void main (void)
   int x = 4, y = 20,  z;
   z =  add (x , y);  //Function Call
   printf ( “The sum is  %d \n ”,  z);

z =  add (x , y); is the function call, and it is calling a function that returns a value

Get The Coding Examples From C Language Code Example Page

Leave a Comment