Wednesday, June 24, 2009

Variables can be declared inside a for loop declaration



NOTE : -
THIS CONTENT IS NOT ORIGINAL

6. Variables can be declared inside a for loop declaration

C++ allows you to declare a variable to be local to a loop:


using namespace std;
#include

int main ()
{
int i; // Simple declaration of i
i = 487;

for (int i = 0; i <>
Output
0
1
2
3
487



In case the variable is not declared somewhere above the loop, you may be tempted to use it below the loop. Some early C++ compilers accept this. Then the variable has the value it had when the loop ended. You shouldn't do this. It's considered bad practice:


using namespace std;
#include

int main ()
{

for (int i = 0; i <>
Gnu C++ compiler complain
t.cpp: In function ‘int main()’:
t.cpp:12: error: name lookup of ‘i’ changed for new ISO ‘for’ scoping
t.cpp:7: error: using obsolete binding at ‘i’



BIBILOGRAPHY / REFERENCE : - http://www.4p8.com/eric.brasseur/cppcen.html

No comments:

3G S

JAIL BREAK

iPHONE

BILL GATES

StEvE JoBs

steve jobs

STEVE JOBS

Steve Jobs

Love Country

SD

Burroughs

Lift

Joseph Johnson

Apple Rainbow

Apple Blue

Apple Laser Printer