234k views
5 votes
Without using a pointer, how can local variables be changed outside a function in C?

a) Using global variables
b) Passing variables by reference
c) Using a return statement
d) None of the above

1 Answer

1 vote

Final answer:

Local variables in C cannot be changed from outside their defining function without using pointers; hence, the correct answer is 'd) None of the above.' Global variables and return statements cannot serve this purpose.

Step-by-step explanation:

To answer the question of how local variables can be changed outside a function in C without using a pointer, let's consider the given options:

  • Using global variables: This is one way to affect a variable outside of a function, but it doesn't involve changing a local variable as global variables have a scope that spans the entire program.
  • Passing variables by reference: In C, this can only be done using pointers, which means this option is not applicable since the condition states no pointers should be used.
  • Using a return statement: Through a return statement, a function can send back a value to the caller; however, this does not 'change' the local variable itself but rather passes a new value back.
  • None of the above: This is the correct answer. In C, without using pointers, it is not possible to directly change local variables of a function from the outside.

Therefore, the correct answer is d) None of the above.

User Plonknimbuzz
by
7.4k points