C++ and Python Quiz

C++ and Python Quiz

Professional Development

25 Qs

quiz-placeholder

Similar activities

Biomechanical/Rehabilitative QUIZ

Biomechanical/Rehabilitative QUIZ

Professional Development

20 Qs

2ND QUIZ AMIP

2ND QUIZ AMIP

Professional Development

20 Qs

Sales and Order Quiz

Sales and Order Quiz

Professional Development

20 Qs

Part 2

Part 2

Professional Development

20 Qs

KUIS UJI KOMPETENSI AGUSTUS 2024

KUIS UJI KOMPETENSI AGUSTUS 2024

Professional Development

20 Qs

Edukasi Rupiah Kepada PERBARINDO Tahun 2024

Edukasi Rupiah Kepada PERBARINDO Tahun 2024

Professional Development

20 Qs

IOT PERTEMUAN 1

IOT PERTEMUAN 1

Professional Development

20 Qs

DTA KBQ Janmashtami Special

DTA KBQ Janmashtami Special

Professional Development

20 Qs

C++ and Python Quiz

C++ and Python Quiz

Assessment

Quiz

Other

Professional Development

Practice Problem

Medium

Created by

Viswathika K

Used 2+ times

FREE Resource

AI

Enhance your content in a minute

Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...

25 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Find the Output
#include using namespace std; int main() { int* a, b; cout << typeid(a).name() << endl; cout << typeid(b).name() << endl; return 0; }

a is an int*, b is an int

Both a and b are int*

Both a and b are int

Compilation error

Answer explanation

a is declared as a pointer to int, but b is just a plain int. Only a gets the * (pointer). b is just a regular int. Pi denotes type Pointer(Int) .i denotes Integer.

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Find the output #include using namespace std; int main() { int p; bool a = true; bool b = false; int x = 10; int y = 5; p = ((x | y) + (a + b)); cout << p; return 0; }

12

0

2

16

Answer explanation

| means bitwise OR operation so x | y (0101 | 1010) will be evaluated to 1111 which is integer 15 and as a is true and b is false so a+b(1 + 0) = 1. So final value of expression in line #10 will be 15 + 1 = 16.

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Find the Output :

    #include <iostream>

    using namespace std;

    int main()

    {

        int a = 5;

        cout << sizeof(++a) <<endl;

        cout << a;

        return 0;

    }

2 5

4 5

4 6

2 6

Answer explanation

In this C++ program, a variable a is initialized with the value 5. The line sizeof(++a) might seem like it would increment a, but it does not. This is because the sizeof operator in C++ is evaluated at compile time and does not actually evaluate the expression inside it. Instead, it only checks the type of the expression, which in this case is int. Therefore, sizeof(++a) simply returns the size of an int, which is typically 4 bytes on most systems.

As a result, the value of a remains unchanged. When the program prints sizeof(++a), it outputs 4, and when it prints a, it outputs 5. This demonstrates that sizeof does not cause side effects or execute any operations on the variables used within it.

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following symbol is used to declare the preprocessor directives in C++?

$

^

#

*

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

How structures and classes in C++ differ?

Structures by default hide every member whereas classes do not

In Structures, members are public by default whereas, in Classes, they are private by default

Structures cannot have private members whereas classes can have

In Structures, members are private by default whereas, in Classes, they are public by default

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What will be the output of the following C++ code?

#include using namespace std; int main () { int a, b, c; a = 2; b = 7; c = (a > b) ? a : b; cout << c; return 0; }

12

14

6

7

Answer explanation

We are using the ternary operator to evaluate this expression. It will return first option, if first condition is true otherwise it will return second

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Find the output #include using namespace std; int main () { int array[] = {0, 2, 4, 6, 7, 5, 3}; int n, result = 0; for (n = 0; n < 7; n++) { result += array[n]; } cout << result; return 0; }

21

27

26

25

Answer explanation

This C++ program calculates the sum of elements in an integer array. The array array[] is initialized with the values {0, 2, 4, 6, 7, 5, 3}. A variable result is used to accumulate the sum and is initialized to 0. The for loop runs from n = 0 to n < 7, meaning it iterates through all 7 elements of the array. In each iteration, the current array element array[n] is added to result. After the loop completes, result holds the total sum of the array elements. Finally, the program prints the sum, which is 27, as the sum of all elements 0 + 2 + 4 + 6 + 7 + 5 + 3 = 27.

Create a free account and access millions of resources

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?