Question:
A variable declared at the start of an if clause's block will be in scope:?
enjoi167
2009-09-26 13:53:18 UTC
A variable declared at the start of an if clause's block will be in scope:

A. Only within the if clause's block, including any nested if statements
B. Within the if clause's block and the blocks of any else clauses in the same if-else or if-else-if statement.
C. Within the if clause's block, but not within any nested if statements
D. Anywhere in the method, following the variable's declaration
Four answers:
Peter H
2009-09-26 14:16:27 UTC
It depends on which language you are using. In C/C++ there will be an opening bracket after the if and before the declaration of the variable. The variable will remain in scope until the corresponding closing bracket. This includes nested if statements, unless another variable with the same name is declared within a nested block. Any else keyword will be the start of a new scope in which the previously declared variable will be out of scope.



In Basic, however, the end of an if block is signalled by an endif keyword, and the else, if there is one, is in the middle. In this case the variable declared at the start of the if will be in scope through the else block until the corresponding endif.
wiltshire
2016-12-04 07:57:43 UTC
hi, I shop my digital mail open and block no person; even those that worry or tell me off. I comprehend the place you're coming from yet even so many blockers right here have a crybaby innovations-set that I disagree with what you're saying, wahhhh, i'm taking my marbles and going homestead! to illustrate the final guy or woman who blocked me did so via fact I reported that Cleopatra became into no longer black Sub Saharan as she concept yet Macedonian from the Ptomely kin. I went directly to indicate out that there became into an Afro - Centrist prof who gave a huge public lecture approximately Aristotle stealing all his ideas from the Black Africans who had it interior the Library of Alexandria... no longer finished till properly after his loss of existence. earlier that a creationist blocked me for affirming that God will ask how believed and behaved in this existence; no longer ask if earth is 6400 or 4.5 billion years old or if guy walked with dinosaurs. Cheers, Michael Kelly
2009-09-26 14:02:54 UTC
B i guess
bernmeister
2009-09-26 18:48:57 UTC
A


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...