May 4, 2011

My C++ Experiments

The following program will access the private variable outside the class which is theoretically not possible in C++.
'info' private variable will be assigned using the ‘int’ pointer variable ‘a’.


class Node
private :
int info;
public :
void disp()

void main()
Node *n;
int *a;
a = (int *) n;

The following program a very interesting example of 'for loop'. Do you think the program will give syntax error or it will go in infinite loop?
It won’t. It will just print ‘1’. To know how, you should learn 'for loop' very carefully or visit me personally or left your email in comments because it is very 

difficult to explain here. 

void main()
int i=0;
for(;i++;cout<<i)  ;


yogeshnc said...

Hello dear, second Program have semicolon (;) at the end of for(); line that why after going to increment part it print 1 and exit becouse of semicolon

Anonymous said...

plz tell me how it works. my email:

Madhuri Kolhe said...

Semicolon will end that for loop at first time.
but as while executing the line at first time will increment the value of i.
so it will print 1.

Tushar T. Chaudhari said...

No guys...there is nothing to do with that semicolon after for loop...

@Ravi it is not possible to explain it through email...otherwise I already did that....

Popular Posts