C++ MCQs with answers Page - 91

Here, you will find a collection of MCQ questions on C++. Go through these questions to enhance your preparation for upcoming examinations and interviews.

To check the correct answer, simply click the View Answer button provided for each question.

Have your own questions to contribute? Click the button below to share your MCQs with others!

+ Add Question

A

Admin • 833.24K Points
Coach

Q. Which part of memory is used for the allocation of local variables declared inside any function.

  • (A) Address Space
  • (B) Heap
  • (C) Stack
  • (D) Depends on Compiler

A

Admin • 833.24K Points
Coach

Q. What is the extension of the executable file produced
after compiling C/C++ code using g++ on Linux?

  • (A) .a
  • (B) .lib
  • (C) .out
  • (D) .exe

A

Admin • 833.24K Points
Coach

Q. Which is the Parent class for all exceptions?

  • (A) std::runtime_error
  • (B) std::exception
  • (C) std::logic_error
  • (D) std::bad_exception

A

Admin • 833.24K Points
Coach

Q. Which exception is thrown when dynamic_cast fails?

  • (A) std::bad_cast
  • (B) std::runtime_error
  • (C) std::logic_error
  • (D) std::bad_typeid

A

Admin • 833.24K Points
Coach

Q. Which Exception is thrown when new fails to allocate memory?

  • (A) std::out_of_range
  • (B) std::runtime_error
  • (C) std::bad_alloc
  • (D) std::exception

A

Admin • 833.24K Points
Coach

Q. Find the output of below program.

Code:
int main()
{
for(int i=1;i<=2;i++)
{
for(int j=i;j<=2;j++)
cout<<i<<@;
}
}
  • (A) 1@2@2@
  • (B) 1@1@2@
  • (C) 1@2@1@
  • (D) 1@2@

A

Admin • 833.24K Points
Coach

Q. How many times mcqbuddy.com is printed here?

Code:
int main()
{

for(int i=0; i< 5; i++);
cout<<"mcqbuddy.com";

return 0;
}
  • (A) 0
  • (B) 1
  • (C) 4
  • (D) 5

A

Admin • 833.24K Points
Coach

Q. Find output of below program.

Code:
int main()
{
int c1,c2;
int a = -8;
int b = 3;
c1 = --a + b;
c2 = a-- + b;
cout<<"c1="<<c1<<", "<<"c2="<<c2<<endl;

return 0;
}
  • (A) c1=-6,c2=-6
  • (B) c1=-4,c1=b-3
  • (C) c1=-7,c2=-3
  • (D) c1=-7,c2=-4

A

Admin • 833.24K Points
Coach

Q. Find the output of below program.

Code:
int main() 
{
int i=0,x=0;

for(i=1;i<10;i*=2)
{
    x++;
    cout<<x;
}
cout<<x;

return 0;
}
  • (A) 12344
  • (B) 123455
  • (C) 12345678910
  • (D) 1234567899

A

Admin • 833.24K Points
Coach

Q. What should be printed on screen?

Code:
int main() 
{
int x = 5;

if(x++ == 5)
cout<<"Five"<<endl;
else
if(++x == 6)
cout<<"Six"<<endl;

return 0;
}
  • (A) Five
  • (B) Six
  • (C) FiveSix
  • (D) None of these