[Show all top banners]

All The Way
Replies to this thread:

More by All The Way
What people are reading
Subscribers
:: Subscribe
Back to: Computer/IT Refresh page to view new replies
 Help Please !!
[VIEWED 3513 TIMES]
SAVE! for ease of future access.
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


 
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


 
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.


 
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) .


 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 90 days
Recommended Popular Threads Controvertial Threads
शीर्षक जे पनि हुन सक्छ।
NRN card pros and cons?
What are your first memories of when Nepal Television Began?
TPS Re-registration case still pending ..
Basnet or Basnyat ??
nrn citizenship
Sajha has turned into MAGATs nest
Nas and The Bokas: Coming to a Night Club near you
डीभी परेन भने खुसि हुनु होस् ! अमेरिकामाधेरै का श्रीमती अर्कैसँग पोइला गएका छन् !
3 most corrupt politicians in the world
अमेरिकामा बस्ने प्राय जस्तो नेपालीहरु सबै मध्यम बर्गीय अथवा माथि (higher than middle class)
if you are in USA illegally and ask for asylum it is legal
Travelling to Nepal - TPS AP- PASSPORT
emergency donation needed
Top 10 Anti-vaxxers Who Got Owned by COVID
निगुरो थाहा छ ??
ढ्याउ गर्दा दसैँको खसी गनाउच
Poonam pandey - death or suicide?
Doctors dying suddenly or unexpectedly since the rollout of COVID-19 vaccines
काेराेना सङ्क्रमणबाट बच्न Immunity बढाउन के के खाने ?How to increase immunity against COVID - 19?
Nas and The Bokas: Coming to a Night Club near you
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters