Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Arguments | Functions
C Basics

bookArguments

Functions can be thought of as mini-factories, taking raw materials and transforming them into various products. Similarly, functions process input data. The input for a function is termed as arguments or parameters.

main.cpp

main.cpp

copy
123456
func_type func_name(arguments) { // The core functionality of the function // The resulting outcome after function execution return function_output; }

As an example, you can design a function to convert degrees to radians:

Main.c

Main.c

copy
123456789101112131415
#include <stdio.h> // My function for conversion degrees to radians // `double degree` is argument double degreesToRadians(double degree) { double rads = (degree * 3.14) / 180; return rads; // Output of function } int main() { double degree = 30; printf("30 degrees equals %.2f radians\n", degreesToRadians(degree)); return 0; }

Scope

Imagine a function call as a portal into a separate, self-contained realm where specific actions take place. Objects birthed in this realm exist solely there, and once the realm ceases to exist, so do they.

For instance, if we declare a variable inside a function, it remains inaccessible from outside that function. The sole piece of information we can extract from a function's execution is what we retrieve using the return statement.

Arguments

Functions can take a variety of arguments: basic data types (like int, char, double), arrays/strings, pointers (teaser!), and even other functions.

It's also important to note that the names of the arguments within the function might differ from the actual data you're passing into it.

int exampleFunc(int inputVar) 
{
    … 
    return result;
}

The variable int inputVar lives only within the scope of the function, acting as a placeholder for the data we want to feed into the function. However, the data types of both the arguments and the actual data passed to the function must align.

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 5. ChapterΒ 3

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Suggested prompts:

Can you explain more about the difference between arguments and parameters?

What happens if I try to access a variable declared inside a function from outside the function?

Can you give more examples of functions with different types of arguments?

Awesome!

Completion rate improved to 2.63

bookArguments

Swipe to show menu

Functions can be thought of as mini-factories, taking raw materials and transforming them into various products. Similarly, functions process input data. The input for a function is termed as arguments or parameters.

main.cpp

main.cpp

copy
123456
func_type func_name(arguments) { // The core functionality of the function // The resulting outcome after function execution return function_output; }

As an example, you can design a function to convert degrees to radians:

Main.c

Main.c

copy
123456789101112131415
#include <stdio.h> // My function for conversion degrees to radians // `double degree` is argument double degreesToRadians(double degree) { double rads = (degree * 3.14) / 180; return rads; // Output of function } int main() { double degree = 30; printf("30 degrees equals %.2f radians\n", degreesToRadians(degree)); return 0; }

Scope

Imagine a function call as a portal into a separate, self-contained realm where specific actions take place. Objects birthed in this realm exist solely there, and once the realm ceases to exist, so do they.

For instance, if we declare a variable inside a function, it remains inaccessible from outside that function. The sole piece of information we can extract from a function's execution is what we retrieve using the return statement.

Arguments

Functions can take a variety of arguments: basic data types (like int, char, double), arrays/strings, pointers (teaser!), and even other functions.

It's also important to note that the names of the arguments within the function might differ from the actual data you're passing into it.

int exampleFunc(int inputVar) 
{
    … 
    return result;
}

The variable int inputVar lives only within the scope of the function, acting as a placeholder for the data we want to feed into the function. However, the data types of both the arguments and the actual data passed to the function must align.

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 5. ChapterΒ 3
some-alt