C programming - Calling a function

htt‮:sp‬//www.theitroad.com

In C programming, you can call a function by using its name followed by parentheses containing the arguments (if any) to be passed to the function. The general syntax for calling a function is as follows:

function_name(argument_list);

In this syntax, function_name is the name of the function you want to call, and argument_list is a comma-separated list of values to be passed as arguments to the function (if the function takes any arguments).

Here's an example of a function call that passes two integers to a function named add that returns the sum of the two integers:

int result = add(5, 7);

In this example, the function add takes two integer arguments, 5 and 7, and returns their sum, which is assigned to the variable result. When the add function is called with these arguments, it will perform the addition operation and return the result to the calling statement.

Note that the data type of the return value must match the data type specified in the function prototype or definition. If the function returns a value but you don't use it, you can call the function without assigning the return value to a variable. For example:

print_hello();

In this example, the function print_hello takes no arguments and returns no value, so it can be called without assigning the return value to a variable.