answersLogoWhite

0


Best Answer

If the variable is declared within the function body, it is a local variable, one that is local to the function. Local variables fall from scope when the function returns, they are only accessible within the function. However, local variables can be returned by value, which creates an automatic variable that is returned to the caller. If the caller does not store the return value, the automatic variable falls from scope when the expression containing the function call ends. However, the expression may evaluate the return value without storing it. Note that functions cannot return local variables by reference since the local variable falls from scope when the function returns.

If the variable is passed as an argument to the function, then the variable is a parameter of the function. Arguments may be passed by value or by reference, depending upon the function signature. Passing by value means the function parameter is a copy of the argument (if the argument is an object, the object's copy constructor is invoked automatically). Thus any changes made to the parameter within the function are not reflected in the argument that was originally passed, and the parameter will fall from scope when the function returns. However, the value of the parameter can be returned as previously explained.

Passing by reference means the function parameter refers directly to the argument that was passed. Thus any changes made to the parameter are reflected in the argument.

Parameters that are declared as constant references assure the caller that the reference's immutable members will not be altered by the function. If the parameter is a non-const reference but the caller does not wish changes to be reflected in the argument, the caller should pass a copy of the argument instead.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is a variable that is used within a function?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Suppose an external variable is defined outside of function A and accessed within the function Does it matter whether the external variable is defined before or after the function. Explain?

No the two work together REALLY


How do you access global variable from within the main function when the local variable is of the same name?

When you acess a global variable inside main function you must use the same name, because the variable declared as global can be accessed by any function/procedure on the class where it was defined.


Explain the scope and visibility of variables in c plus plus function?

If you define a variable inside of your function, the variable can be referred and used only inside of that function. It means that you will not able to use the variable in another function (including main). Area of code where your variable can be used after declaration is usually called visibility of the variable.


Why all variables are declared with in the function?

It is not necessary to to declare variables inside the function in C. If you declare a variable inside a function, the variable becomes local for the function and another variable of same name can be declared in any other function, but you can not use the variable declared in other function. When you declare any variable outside the function body then the variable becomes global and can be used in any function of the program. Note: errno is an example for a variable declared outside any function.


What is the definition of prefix function?

A function that is used before an variable to increase or decrease its value

Related questions

What do you call a variable of a function that is active only within the procedure or its function?

local variable


How you can declare local variable?

variable exit within a function and curly braces is local variable int main() { int x; }


Suppose an external variable is defined outside of function A and accessed within the function Does it matter whether the external variable is defined before or after the function. Explain?

No the two work together REALLY


What ia call by value?

Call by value it's a mechanism to design to pass arguments to functions. When you call by value a variable within the list of argument of function, it means you ask to provide a copy of the variable. And if it happens that you change the variable within your function, it's not gong to change the original variable.


How do you access global variable from within the main function when the local variable is of the same name?

When you acess a global variable inside main function you must use the same name, because the variable declared as global can be accessed by any function/procedure on the class where it was defined.


Explain the scope and visibility of variables in c plus plus function?

If you define a variable inside of your function, the variable can be referred and used only inside of that function. It means that you will not able to use the variable in another function (including main). Area of code where your variable can be used after declaration is usually called visibility of the variable.


Why all variables are declared with in the function?

It is not necessary to to declare variables inside the function in C. If you declare a variable inside a function, the variable becomes local for the function and another variable of same name can be declared in any other function, but you can not use the variable declared in other function. When you declare any variable outside the function body then the variable becomes global and can be used in any function of the program. Note: errno is an example for a variable declared outside any function.


What is prefix of function?

A function that is used before an variable to increase or decrease its value


What does void mean in C programming?

It's a dummy variable for functions. It's usually used when there's no actual value returned from the function, but you want the operations within the function to be caused to occur.


What is the Definition to function?

a table used to show values of the variable expression for a given function


What is the definition of prefix function?

A function that is used before an variable to increase or decrease its value


How do you create static variables in PHP?

Use the "static" keyword to declare a static variable within a function like shown below. <?php function fun() { static $variable; static $another_variable = ''; } ?>