int a = 10;

void main()
{
int a = 20;
cout << a << ::a;
}
The output of this program is

Options
- Syntax error
- 10 20
- 20 10
- 20 20


CORRECT ANSWER : 20 10

Discussion Board
Correct code

#include
using namespace std;
int a = 10;

int main()
{
int a = 20;
cout << a <<" " <<::a;
return 0;
}

jjasdf 05-3-2019 06:01 PM

C++ - Trace the Output

The above program can have same name for local and global variables but value of local variable inside a function will take preference. When the above code is compiled and executed, it produces the following result:
2010

Prajakta Pandit 01-25-2017 04:06 AM

No

The output will be
2010

sdp 05-4-2015 07:03 AM

Write your comments

 
   
 
 

Enter the code shown above:
 
(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)


Advertisement