Function Arguments

By: Jesse Miller

Data can be passes as arguments to custom functions that can then use that data in the execution of their statements. The function prototype must include the name and data type of each argument.

It is important to recognize that in C programming the data is passed `by value` to the variable specified as the function argument. This is different to some other programming languages, such as Pascal, whose arguments are passed by reference. Arguments are passed where the function has access to the original data, not just a local copy. Passing data by value assigns the value to a variable in the called function. The function can manipulate this copy but it does not affect the original data value.

The arguments in a function prototype are known as the `formal parameters` of the function. These may be of different data types and multiple arguments can be specified for a single function if separated by a comma. A function prototype with arguments of each of the four data types could be with arguments such as char, int, float, double, etc.

The compiler checks that the formal parameters specified in the function`s prototype match those of the actual function definition and will report an error if they do not match.

The display () function has an argument named str that is an array of the char data type, capable of storing a string of text. Inside the main() function a string is assigned to another array named msg. When the display() function is called, the string in the msg variable is passed to the str variable, which is then displayed by a call to the printf () function.

Both other custom functions, square() and cube(), have a single argument of the int data type. When these functions are called from within the main() function an integer value is passed to their argument. This value is used in a piece of arithmetic then the result is returned to the main() function. The call to the square() function assigns the returned value to an int variable-which is subsequently displayed by the printf() function. The call to the cube() function is itself made from within a call to the printf() function so is immediately displayed.

Quick Note: Taking the Nonsense out of looking for the right spyware remover

If you really want to take the work out of looking for that right Spyware Protection from a go to the Internet and get a or a Free
Download, In order to prevent your vital information from being ripped from your computer get your Remover Today.

The argument names used in the function definition can differ from those used in the function prototype, but the argument data types, number and order must be the same.

Top Searches on
Computers
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 

» More on Computers