Search Header Logo

C++ MCQ

Authored by Divya Kumawat

Education

1st - 5th Grade

10 Questions

Used 2+ times

C++ MCQ
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

The access specifier for members x of a class in C++?
class Sample {

int x;

};

public

private

protected

None of the above

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Consider the code below. What will it print?
class Demo {

public:

int a;

};

int main() {

Demo d;

d.a = 10;

std::cout << d.a;

return 0;

}

0

10


Garbage value

Compilation error

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the lifetime of a local object inside a function?

Entire program execution

Only until function exits

Until program ends

Until another object is created

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which object is destroyed automatically at the end of program?

Local object

Static object inside function

Global object

Dynamic object

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the correct way to access a static member without creating an object?

Sample s; s.x;

Sample::x;

s.x;

static Sample::x;

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following is TRUE?

Static variable inside a class cannot be private

Static variable belongs to class, not object

Local objects persist throughout program

Global objects are destroyed after main

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What will be the output of this code?

#include <iostream>

class Test {

public:

Test() { std::cout << "Hello"; }

};

int main() {

static Test t;

}

Nothing

Hello

Hello Hello

Compilation error

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?