MTEL Digital Literacy and Computer Science

Category - Digital Lit and CS

In a C-like programming language, which of the following outcomes will occur if a function's local variable has the same name as a global variable?
  1. The value of the local variable will be assigned to the global variable.
  2. Within the function, the variable name will refer to the local variable.
  3. The function will not compile and will give an error message.
  4. The values of the global and local variables will always be the same.
Explanation
Correct Response: B. The variable names of local variables take precedence and shield access to global variables of the same name. A is incorrect because same-named local and global variables do not interact in this way. C is incorrect because it is syntactically allowable to give a local and global variable the same name. D is incorrect because same-named local and global variables do not interact in this way.
Was this helpful? Upvote!
Login to contribute your own answer or details

Top questions

Related questions

Most popular on PracticeQuiz