Why am I not getting an error?
Natsu
2016-08-13T16:27:41
In the following program:
#include <iostream>
using namespace std;
int main(){
int i = 99;
for(int i = 1; i <= 10; i++)
{
cout << i << endl;
}
cout << endl << endl;
cout << i << endl;
return 0;
}
I am not getting an error on compilation.
My question is why this is happening.
The int variable i was declared twice. The first time i was declared in the main() function and thus its scope will be this whole main() function including the for loop. The second time i was declared with the for loop and thus its scope will be only the for loop. So, now inside the scope of the for loop there exists two int variablesi . Shouldn't this be a cause of error? And if not why?
Second thing is the output I am getting:
1
2
3
4
5
6
7
8
9
10
99
I also don't understand the output. Why after the execution of the for loop, the value of i that is being printed is 99 and not 10.
Copyright License: Author:「Natsu」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer. Link to:https://stackoverflow.com/questions/38930800/why-am-i-not-getting-an-error
About “Why am I not getting an error?” questions
I am getting an error in PrintF in the following java code.
The Error Is :
The method printf(String, Object[ ]) in the type PrintStream is not
applicable for the arguments (String, int)
The ...
|
In the following program:
#include <iostream>
using namespace std;
int main(){
int i = 99;
for(int i = 1; i <= 10; i++)
{
cout << i << endl;
|
I have imported mysql data from my local machine to webserver through phpmyadmin and when I run my script I am getting this error
Illegal mix of collations (utf8_general_ci,IMPLICIT) and (
|
Why Am I getting an error. In eclipse it says constructor call should be the first line. It is the first line. or you can not extend Main?
import javax.swing.JFrame;
import javax.swing.JLabel;
|
This is the code I did
SELECT TOP 5 ContactName FROM Customers
INNER JOIN [Order Details]ON OrderId =
CustomerID
INNER JOIN Orders ON ProductID = OrderID
WHERE UnitPrice >= 25000
ORDER BY
|
I have typed the following in matlab:
>> I=imread('23X41.jpg');
>> fun = @(x) sum(x(:).^2)/sum(x(:)).^2;
>> en= nlfilter(I,[4 4],fun);
And, got the following error?
??
|
Why am I getting these errors?
alt text http://img39.imageshack.us/img39/2203/help.tif
It says:
Error: Request for member "jokeTableView" in something not a struction or union
What does that m...
|
I know that runtime error occurs when program consumes large memory or divide by 0 somewhere.
this is the code which prints all the numbers until user types 42.(does not print 42).
#include<std...
|
I having been working with Adobe After Effects and want to export some comps with Adobe Media Encoder, but when I try to export a comp from After Effects using Media Encoder, I get these error mess...
|
I have started working on dojo and osm recently, so it might be a simple question but am not able to figure out why I am getting this error. the dojo code I have to load the map from osm is as belo...
|
|
|