C++ scope resolution operator tell the output and give the reason

5 pts.
Tags:
C++
Scope resolution operator usage
#include<iostream.h> #include<conio.h> int a=10; void main() { int a=5; clrscr();

cout<<::a++<<++a<<endl; for(int i=1;i<=3;i++)  { cout<<a++<<::a+2;

  getch();  }

}



Software/Hardware used:
turbo C++

Answer Wiki

Thanks. We'll let you know when a new response is added.

the answer to the above problem must be:
106
613713813

solution:
cout<<::a++<<++a;
it prints 10 and increments the global a value by one and increments local a value and prints it 6

inside loop
cout<<a++<<::a+2;

first execution
6 13 since a++ prints 6 and increments = 6+1 = 7 , ::a+2 = 11+2
second execution
7 13 a++ prints 7 and increments = 7+1 = 8, ::a+2 = 11+2 since scope a is not incremented
third execution
8 13 same type of calculation

so the o/p is
106
613713813

tel me if correct

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • carlosdl
    You should run the code and analyze the output to get the answer.
    68,330 pointsBadges:
    report
  • carlosdl
    You are correct Nsn. Usually, we don't answer this kind of question here, as it is clearly a homework assignment, and giving the answer to the OP is not going to help him (her).
    68,330 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following