
C++ and Python Quiz
Quiz
•
Other
•
Professional Development
•
Practice Problem
•
Medium
Viswathika K
Used 2+ times
FREE Resource
Enhance your content in a minute
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
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
Edukasi Rupiah Kepada PERBARINDO Tahun 2024
Quiz
•
Professional Development
20 questions
World Book Day 2020
Quiz
•
KG - Professional Dev...
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...
Popular Resources on Wayground
5 questions
This is not a...winter edition (Drawing game)
Quiz
•
1st - 5th Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
10 questions
Identify Iconic Christmas Movie Scenes
Interactive video
•
6th - 10th Grade
20 questions
Christmas Trivia
Quiz
•
6th - 8th Grade
18 questions
Kids Christmas Trivia
Quiz
•
KG - 5th Grade
11 questions
How well do you know your Christmas Characters?
Lesson
•
3rd Grade
14 questions
Christmas Trivia
Quiz
•
5th Grade
20 questions
How the Grinch Stole Christmas
Quiz
•
5th Grade
Discover more resources for Other
26 questions
Christmas Movie Trivia
Lesson
•
8th Grade - Professio...
25 questions
Christmas Movies
Quiz
•
Professional Development
20 questions
Christmas Trivia
Quiz
•
Professional Development
15 questions
Fun Holiday Trivia
Quiz
•
Professional Development
25 questions
Name That Tune - Christmas
Quiz
•
Professional Development
29 questions
Christmas Song Emoji Pictionary
Quiz
•
Professional Development
9 questions
Holiday Movie Trivia
Lesson
•
Professional Development
34 questions
Winter Trivia
Quiz
•
Professional Development
