Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
What is output of the following programme?
#include <iostream>

using namespace std;

int x = 19; int main()

{

int x = 21;

(

int x

cout <<::X<<x<<::x<<"\n”;

}

return 0;

a.="" 414141="" b.="" 194121="" c.="" 214121="" d.="" 194119

<b="">What I have tried:

I have tried many websites but not getting the answe,so please help me out to find this answer.
Posted
Updated 16-Jun-22 20:09pm
Comments
jeron1 16-Jun-22 11:58am    
Nothing, it doesn't compile.
merano99 16-Jun-22 16:19pm    
The source code is clearly C++, but tagged as C.
Because of the many invalid codes, it will not show anything until the code is corrected.

None of the above: it won't compile ...
Errors
main.c: In function ‘main’:
main.c:19:4: error: expected ‘)’ before ‘x’
   19 | int x
      |    ^~
      |    )
main.c:17:1: note: to match this ‘(’
   17 | (
      | ^
main.c:21:21: warning: missing terminating " character
   21 | cout <<::X<<x<<::x<<"\n";
      |                     ^
main.c:21:21: error: missing terminating " character
   21 | cout <<::X<<x<<::x<<"\n";
      |                     ^~~~~~~
main.c:23:1: error: expected expression before ‘}’ token
   23 | }
      | ^
main.c: At top level:
main.c:25:1: error: expected identifier or ‘(’ before ‘return’
   25 | return 0;
      | ^~~~~~
main.c:26:1: error: expected identifier or ‘(’ before ‘}’ token
   26 | }
      | ^
 
Share this answer
 
Comments
CPallini 17-Jun-22 2:10am    
5.
As correctly pointed out by Griff, your code doesn't compile.
The following one
C++
#include <iostream>
using namespace std;

int x = 19;
int main()
{
  int x = 21;
  {
    int x = 42;
    cout << ::x << ", " << x << ", " << ::x << "\n";
  }
  return 0;
}
makes the compiler complain a bit
warning: unused variable ‘x’ [-Wunused-variable]
    7 |  int x = 21;

however it compiles and runs, producing the (expected) output
19, 42, 19
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900