Tuesday, June 23, 2009

Variable declarations can be put inside the code without using hooks



NOTE : -
THIS CONTENT IS NOT ORIGINAL

4. Variable declarations can be put inside the code without using hooks

Variables can be declared anywhere inside the code:


using namespace std;
#include

int main ()
{
double a;

cout << "Hello, this is a test program." << endl;

cout << "Type parameter a: ";
cin >> a;

a = (a + 1) / 2;

double c;

c = a * 5 + 1;

cout << "c contains : " << c << endl;

int i, j;

i = 0;
j = i + 1;

cout << "j contains : " << j << endl;

return 0;
}


Output
Hello, this is a test program.
Type parameter a: 7
c contains : 21
j contains : 1



Maybe try to use this feature to make your source code more readable and not to mess it up.

Like in C, variables can be encapsulated between { } blocks. Then they are local in scope to the zone encapsulated between the { and }. Whatever happens with such variables inside the encapsulated zone will have no effect outside the zone:


using namespace std;
#include

int main ()
{
double a;

cout << "Type a number: ";
cin >> a;

{
int a = 1;
a = a * 10 + 4;
cout << "Local number: " << a << endl;
}

cout << "You typed: " << a << endl;

return 0;
}


Output
Type a number: 9
Local number: 14
You typed: 9




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