Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
219 views
in Information Technology by (101k points)
closed by

What is the output of the following C++ program?

#include <iostream.h>

int x = 7;

void showx ();

void showxagain ();

int main ()

{

       showx ();

       showx ();

       showxagain ();

}

void showx ()

{

       int x = 34;

       cout << x++ << endl;

}

void showxagain ()

{

       cout << x++ < endl;

}


1.

35

36

37


2.

34

34

7


3.

35

36

8


4.

35

35

8

1 Answer

0 votes
by (108k points)
selected by
 
Best answer
Correct Answer - Option 2 :

34

34

7


#include <iostream.h>

int x = 7;

void showx ();

void showxagain ();

int main ()

{

       showx ();   // result as 34

       showx ();  // result as 34

       showxagain (); // result as 7

}

void showx ()

{

       int x = 34;

       cout << x++ << endl;    //display output 34 as x is a local variable 

}

void showxagain ()

{

       cout << x++ < endl;      // display output 7 as x is global variable here so value of x will be 7

}

Therefore Answer will be Option 2 i.e,

34

34

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...