473,413 Members | 1,807 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

What C++ Standard about this?

dh
Hi all,

int a = 1;

for(int a = 12; ...)
{
....
}

// Does value of a here have anything to do with "int a = 1;" scope, or the
"for" scope?

Thanks,
DH
Jul 22 '05 #1
2 1141
>Does value of a here have anything to do with "int a = 1;" scope, or
the
"for" scope?


The "a" in the for loop is in the scope of for loop alone and will not
have any effect on "a" before for loop.

Regards
Shan

Jul 22 '05 #2
dh wrote:
Hi all,

int a = 1;

for(int a = 12; ...)
{
....
}

// Does value of a here have anything to do with "int a = 1;" scope, or the
"for" scope?


The second 'a' has scope from it's declaration until the end of the for
loop, it 'hides' the first 'a' meantime. The first 'a' will be used ( if
at all ) either up until the for and/or after the closing brace of the
for. ( NB. It's legal but I think confusing practise to do this ).

--

Cheers
--
Hewson::Mike
"This letter is longer than usual because I lack the time to make it
shorter" - Blaise Pascal
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Alexander Stippler | last post by:
Hi, what about "not a number"? What does the standard enforce, what not? I read in the C standard, that NAN is defined if and only if the implementation supports quiet NaNs for the float type....
7
by: red floyd | last post by:
Given function pointer, say void (*func)(void*), what's the best way to display it on an iostream? as far as I can tell, there is no default overload for operator<<, and a function pointer...
23
by: herrcho | last post by:
What's the difference between STDIN and Keyboard buffer ? when i get char through scanf, i type in some characters and press enter, then, where do the characters go ? to STDIN or Keyboard...
4
by: Luke Wu | last post by:
I am just wondering what the following terms usually mean: 1) "Standard C" 2) "K&R C" 3) "ANSI C" I am pretty sure "ANSI C" usually refers to the C89 standard, but what
11
by: red floyd | last post by:
I have a copy of the C++ standard. Unfortunately, I don't have a copy of the C89 standard, and the question I have is related to something incorporated by reference. Specifically, what does the...
12
by: Benjamin B. | last post by:
Hi everyone, in this thing I inherited there's a statement like this: a &= ~b; where a is an int and b has been declared this way: const b = 0x0002;
29
by: VirtualDev | last post by:
What is the future of C++?, and what is the C++0x? and is it really going to include a standard portable libraries for GUI, networking, embedded systems and so on?
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
132
by: Frederick Gotham | last post by:
If we look at a programming language such as C++: When an updated Standard comes out, everyone adopts it and abandons the previous one. It seems though that things aren't so clear-cut in the C...
36
by: Pat | last post by:
Hi, I've run into a strange problem, but one that seems like it might be fairly common. I have a single base class, from which several other classes are derived. To keep the example simple,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.