hello guys,

I came across a strange thing when doing program in c++ in visualc++ environment.just run this code and after entering the array elements press up arrow and down arrow.

Here's the code

#include<iostream.h>

void main()
{
int arr[5];
cout<<"Enter the array elements : "<<endl;
for(int i=0;i<5;i++)
cin>>arr;
cout<<"\n\n";
for(i=0;i<5;i++)
{
cout<<"The element no."<<i<<" is "; \\PRESS THE DIRECTION KEYS NOW
cin>>arr;
}
cout<<"\n\n";
}

I came across a strange thing when doing program in c++ in visualc++ environment.just run this code and after entering the array elements press up arrow and down arrow.

Would you mind telling us what this "strange thing" was?

Or might you be marvelling at the command shell in which your code is running? (F7 is really cool, too!)

just run this code and after entering the array elements press up arrow and down arrow

I did so but nothing unusual happened.

But ur code just reminded me of a question that i always wanted to ask,

for(int i=0;i<5;i++)
cin>>arr[i];

As u can c u declared the int i within the for loop, so this makes it local to the block of this for loop and should not be used outside this for loop. So the following code should produce some compile time error saying undeclared variable i.

for(i=0;i<5;i++)
{
cout<<"The element no."<<i<<" is ";
cin>>arr[i];
}

That is exactly what happens with the latest borland 5.5 compiler. However, my Visual C++ doesnt produce any error and the program runs fine. Why is this so, why is this two compiler behaving differently. Has it not been standarized that i's scope is limited within the block of "for" loop?

However, my Visual C++ doesnt produce any error and the program runs fine. Why is this so, why is this two compiler behaving differently. Has it not been standarized that i's scope is limited within the block of "for" loop?

MSVC6 just got it wrong.

Would you mind telling us what this "strange thing" was?

Or might you be marvelling at the command shell in which your code is running? (F7 is really cool, too!)

i am running my code in msvc++ 6.0

ya.the thing i wondered was.. it happens even after giving ignore() and clear() commnds.So it doe not matters with the buffer.So tell me how the previous input stays in that keys particularly?

Again, are you investigating your program or the shell in which it is running?

I am guessing that you are in Windows. I think you are confused by Doskey.

[edit]Go to "Command Prompt" and enter "help doskey". Is this the same behavior you see?

Strange, but i m using MS Visual C++ 6.0, too.

I am at a loss as to whether you are asking a question in regard to the "strange" behavior, or if you are trying to ask a question about the fact the MSVC6 messed up the scoping rules, or whether there is any question in that at all.

To dave:
I was wondering why my MS visual c++ 6.0 is not pointing that out (the thing with i's scopes) as an error, but ur MSVC6 is. My friend's MSVC6 doesnt produce an error either. Since i do not expect u to know what is wrong with my particular compiler without seeing it for urself, i said "Strange, but i m using MS Visual C++ 6.0, too." Got it big bro?

To dave:
I was wondering why my MS visual c++ 6.0 is not pointing that out (the thing with i's scopes) as an error, but ur MSVC6 is. My friend's MSVC6 doesnt produce an error either.

My MSVC6 isn't. My Borland 5.5 is. And I happen to be aware of the issue with MSVC6. They got it wrong (among other things). Borland 5.5 didn't.

hello guys,

I came across a strange thing when doing program in c++ in visualc++ environment.just run this code and after entering the array elements press up arrow and down arrow.


hi,
thread.
Actually this application is a win32 console application in vc++.
it runs in the dos mode.
if you know the format of dos then you will observe that if you have written something above and you start pressing the direction keys then it will reprint the above written statements.
i think iam right.
from umair khan.

My MSVC6 isn't. My Borland 5.5 is. And I happen to be aware of the issue with MSVC6. They got it wrong (among other things). Borland 5.5 didn't.

Well that clears it up, thanx Dave.

This article has been dead for over six months. Start a new discussion instead.