
C++ and Python Quiz

Quiz
•
Other
•
Professional Development
•
Hard
Viswathika K
Used 1+ times
FREE Resource
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
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
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
Similar Resources on Wayground
20 questions
PEMOGRAMAN BERORINTASI OBJECK XII_I

Quiz
•
Professional Development
20 questions
Programowanie

Quiz
•
1st Grade - Professio...
22 questions
Day 2 Quiz 10th Aug

Quiz
•
Professional Development
20 questions
Introduccion a la Programacion - Fundamentos de Programacion -P2

Quiz
•
Professional Development
20 questions
Quiz on machine learning

Quiz
•
Professional Development
22 questions
Funções e Estruturas em Programação C - Parte I

Quiz
•
9th Grade - Professio...
20 questions
CSS Unit 1

Quiz
•
Professional Development
20 questions
Bahasa dan Software Compiler Pemrograman Mikrokontroler

Quiz
•
Professional Development
Popular Resources on Wayground
18 questions
Writing Launch Day 1

Lesson
•
3rd Grade
11 questions
Hallway & Bathroom Expectations

Quiz
•
6th - 8th Grade
11 questions
Standard Response Protocol

Quiz
•
6th - 8th Grade
40 questions
Algebra Review Topics

Quiz
•
9th - 12th Grade
4 questions
Exit Ticket 7/29

Quiz
•
8th Grade
10 questions
Lab Safety Procedures and Guidelines

Interactive video
•
6th - 10th Grade
19 questions
Handbook Overview

Lesson
•
9th - 12th Grade
20 questions
Subject-Verb Agreement

Quiz
•
9th Grade