[VIEWED 4203
TIMES]
|
SAVE! for ease of future access.
|
|
|
All The Way
Please log in to subscribe to All The Way's postings.
Posted on 12-09-08 10:24
PM
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
Hey Guys, help me here
For the following code, (a) Is that legal to write the code in Line 12? If yes, what is the value of b in Line 12? 5pt (b) Is that legal to write the code in Line 15? If yes, what is the value of c in Line 15? 5pt
1 int a = 0; 2 3 if (a <= 10) { 4 int b = 20; 5 cout << "b = 20\n"; 6 } 7 else { 8 if (a == 12) { 9 int c = 30; 10 cout << "c = 30\n"; 11 } 12 cout << "b = " << b << endl; // Line 12 13 } 14 15 cout << "c = " << c << endl; // Line 15
|
|
|
|
Raxi
Please log in to subscribe to Raxi's postings.
Posted on 12-10-08 12:08
AM
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
Looks like line 12 is legal if '}' after line 12 is assumed as close for main.
The value of b then depends on the value of n which is not specified in your code.
good luck
|
|
|
Raxi
Please log in to subscribe to Raxi's postings.
Posted on 12-10-08 12:10
AM
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
opps... sorry.... the value of b in line 12 will be 20.
since cout << "b = 20\n"; doesnot make any differece in the value of b.
|
|
|
madhab6
Please log in to subscribe to madhab6's postings.
Posted on 12-10-08 12:26
AM
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
try to understand the concept of global and local variable declaration in C++ programming.
After understanding these concepts u'll know that this program is illegal (same word that u like to use I suppose :D) .
|
|