
C++ and Python Quiz

Quiz
•
Other
•
Professional Development
•
Medium
Viswathika K
Used 2+ 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
VLSI - Mock Test

Quiz
•
Professional Development
20 questions
TIU (numerik)

Quiz
•
Professional Development
27 questions
Python-Week5

Quiz
•
University - Professi...
25 questions
PRETEST UPSKILLING PENDAMPING LKS

Quiz
•
Professional Development
20 questions
Quiz Excel

Quiz
•
Professional Development
21 questions
Bỏng ngô hay Bỗng dưng muốn

Quiz
•
Professional Development
30 questions
Ôn tập GIỮA HK2 Tin học 10 (2022-2023)

Quiz
•
Professional Development
21 questions
Computational Thinking

Quiz
•
Professional Development
Popular Resources on Wayground
10 questions
Lab Safety Procedures and Guidelines

Interactive video
•
6th - 10th Grade
10 questions
Nouns, nouns, nouns

Quiz
•
3rd Grade
10 questions
9/11 Experience and Reflections

Interactive video
•
10th - 12th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
11 questions
All about me

Quiz
•
Professional Development
22 questions
Adding Integers

Quiz
•
6th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
9 questions
Tips & Tricks

Lesson
•
6th - 8th Grade
Discover more resources for Other
11 questions
All about me

Quiz
•
Professional Development
10 questions
How to Email your Teacher

Quiz
•
Professional Development
15 questions
Fun Random Trivia

Quiz
•
Professional Development
22 questions
Anne Bradstreet 1612-1672

Quiz
•
Professional Development
18 questions
Spanish Speaking Countries and Capitals

Quiz
•
KG - Professional Dev...
14 questions
Fall Trivia

Quiz
•
11th Grade - Professi...
15 questions
Disney Characters Quiz

Quiz
•
Professional Development
15 questions
Quiz to Highlight Q types & other great features in Wayground

Quiz
•
Professional Development