
C++ and Python Quiz
Authored by Viswathika K
Other
Professional Development
Used 2+ times

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
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.
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?
Similar Resources on Wayground
20 questions
Cinefilos
Quiz
•
KG - Professional Dev...
20 questions
SAF & APUPPTPPPSPM
Quiz
•
Professional Development
20 questions
April Safetyfirst Campaign Quiz
Quiz
•
Professional Development
20 questions
DPB2012 Entrepreneurship
Quiz
•
Professional Development
20 questions
Integria - Rebuttals
Quiz
•
Professional Development
20 questions
GKC - Weekly Quiz 11 - Dinosaurs
Quiz
•
1st Grade - Professio...
20 questions
Edukasi Rupiah Kepada PERBARINDO Tahun 2024
Quiz
•
Professional Development
20 questions
World Book Day 2020
Quiz
•
KG - Professional Dev...
Popular Resources on Wayground
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
22 questions
fractions
Quiz
•
3rd Grade
20 questions
Main Idea and Details
Quiz
•
5th Grade
20 questions
Context Clues
Quiz
•
6th Grade
15 questions
Equivalent Fractions
Quiz
•
4th Grade
20 questions
Figurative Language Review
Quiz
•
6th Grade
Discover more resources for Other
10 questions
How to Email your Teacher
Quiz
•
Professional Development
6 questions
3RD GRADE DECLARATION OF INDEPENDENCE EXIT TICKET
Quiz
•
Professional Development
19 questions
Black History Month Trivia
Quiz
•
6th Grade - Professio...
22 questions
Multiplying Exponents with the Same Base
Quiz
•
9th Grade - Professio...
40 questions
Flags of the World
Quiz
•
KG - Professional Dev...