Calling a Function

To call a function, we use the function name followed by a pair of parentheses enclosing the arguments (if any). The arguments are the values that are passed to the function when it is invoked. The arguments must match the number and type of the parameters declared by the function.

For example, the following code calls the max function with two arguments:

int a = 10;

int b = 20;

int c = max(a, b); // c will be assigned 20

When a function is called, the control passes from the calling code to the function body. The function executes its statements and returns a value (if any) to the calling code. The control then resumes from where it left off in the calling code.

Functions in Objective-C

Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. It is the main programming language used by Apple for the OS X and iOS operating systems and their respective application programming interfaces (APIs), Cocoa and Cocoa Touch.

One of the features of Objective-C is that it supports functions, which are named blocks of code that can be called upon to perform a specific task. Functions can be provided with data on which to perform the task and can return a result to the code that called them. Functions can help to organize the code, avoid repetition, and improve readability and maintainability.

Similar Reads

Defining and Declaring a Function

A function definition in Objective-C consists of two parts: a function header and a function body. The function header specifies the name, return type, and parameters of the function. The function body contains a collection of statements that define what the function does....

Calling a Function

To call a function, we use the function name followed by a pair of parentheses enclosing the arguments (if any). The arguments are the values that are passed to the function when it is invoked. The arguments must match the number and type of the parameters declared by the function....

Passing Arguments and Return Values

There are two ways of passing arguments to a function, By value and By reference....

Differentiating Between Functions and Methods

...

Using Built-in Functions from the Objective-C Foundation Framework

...