4 In C language if we have to access a variable inside a fun

4. In C++ language, if we have to access a variable inside a function, then it can be done

(3 points)

a) By passing variable by value to function argument

b) By passing reference of variable to function argument

c) By declaring variable as the global

d) None of the above

Solution

a) By passing variable by value to function argument:

If we pass variable by value then the copy of the variable will be created not the actual variable hence its not a correct option

b) By passing reference of variable to function argument

If variable is passed by reference then the function will have an access to the actual variable not the dummy one hence it is the correct option and the correct way to access a variable inside a function.

c) By declaring variable as the global

If we declare variable as a global then this variable will be accessible in all the functions which we might not want hence it is not the correct option.

4. In C++ language, if we have to access a variable inside a function, then it can be done (3 points) a) By passing variable by value to function argument b) By

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site