The Wayback Machine - https://web.archive.org/web/20240930184818/https://www.geeksforgeeks.org/c-programming-multiple-choice-questions/
Open In App

C++ Programming Multiple Choice Questions

Last Updated : 05 Dec, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

C++ is the most used and most popular programming language developed by Bjarne Stroustrup. C++ is a high-level and object-oriented programming language. This language allows developers to code clean and efficient code for large applications and software like software/Application development, game development, and operating system programming.
In this C++ MCQs Article, We’ll cover the basic to advanced C++ Multiple Choice Questions and Answers on topics array, pointers, linked lists, functions, OOPs, loops, etc.

C++ Output Question sets:

C++ Topic wise quizzes:

 


Similar Reads

Assigning multiple characters in an int in C language
Consider the following C program. #include <stdio.h> int main(void) { int a = 'd'; printf("%d\n", a); /*OUTPUT - 100 (ASCII Code for character d)*/ int b = 'dd'; printf("%d", b); /*OUTPUT - 25700 (Explanation in detail given below)*/ return 0; } Output : 100 25700 We can easily guess that the output for 'd' is 100 as 100 i
1 min read
error: call of overloaded ‘function(x)’ is ambiguous | Ambiguity in Function overloading in C++
Pre-requisite: Function Overloading in C++ Function overloading is a feature of object-oriented programming where two or more functions can have the same name but different parameters. When a function name is overloaded with different jobs it is called Function Overloading. Two or more functions are said to be overloaded if they differ in any of th
9 min read
unsigned specifier (%u) in C with Examples
The format specifier is used during input and output. It is a way to tell the compiler what type of data is in a variable during taking input using scanf() or printing using printf(). Some examples are %c, %d, %f, %u, etc. This article focuses on discussing the format specifier for unsigned int %u. The %u is an unsigned integer format specifier. It
2 min read
How to show full column content in a PySpark Dataframe ?
Sometimes in Dataframe, when column data containing the long content or large sentence, then PySpark SQL shows the dataframe in compressed form means the first few words of the sentence are shown and others are followed by dots that refers that some more data is available. From the above sample Dataframe, we can easily see that the content of the N
5 min read
Different ways to copy a string in C/C++
Copying a string is a common operation in C/C++ used to create a duplicate copy of the original string. In this article, we will see how to copy strings in C/C++. Methods to Copy a String in C/C++1. Using strcpy() We can use the inbuilt function strcpy() from <string.h> header file to copy one string to the other. strcpy() accepts a pointer t
15+ min read
Runtime Errors
Runtime Errors:A runtime error in a program is an error that occurs while the program is running after being successfully compiled.Runtime errors are commonly called referred to as "bugs" and are often found during the debugging process before the software is released.When runtime errors occur after a program has been distributed to the public, dev
7 min read
Output of C++ programs | Set 50
Predict the output of the following C++ programs: Question 1: C/C++ Code #include <cstdlib> #include <iostream> using namespace std; int main() { int ran = rand(); cout << ran << endl; return 0; } Output: 1804289383Explanation: As the declared number is an integer, It will produce the random number from 0 to RAND_MAX. The va
4 min read
delete keyword in C++
delete is an operator that is used to destroy array and non-array(pointer) objects which are dynamically created by the new operator. delete can be used by either using the delete operator or delete [ ] operator.The new operator is used for dynamic memory allocation which stores variables on heap memory.This means the delete operator deallocates me
4 min read
Output of C++ programs | Set 47 (Pointers)
Prerequisite : Pointers in C/C++ 1. What will be the output of the following program? #include <iostream> using namespace std; int main() { int a = 32, *ptr = &a; char ch = 'A', &cho = ch; cho += a; *ptr += ch; cout << a << ", " << ch << endl; return 0; } Options: a. 32, A b. 32, a c. 129, a d. 129, A
4 min read
Output of python program | Set 12(Lists and Tuples)
Prerequisite: List and Tuples Note: Output of all these programs is tested on Python3 1) What is the output of the following program? C/C++ Code L1 = [] L1.append([1, [2, 3], 4]) L1.extend([7, 8, 9]) print(L1[0][1][1] + L1[2]) a) Type Error: can only concatenate list (not "int") to list b) 12 c) 11 d) 38 Ans: (c) Explanation: In the print(), indexi
3 min read
Output of Python program | Set 6 (Lists)
Prerequisite - Lists in Python Predict the output of the following Python programs. These question set will make you conversant with List Concepts in Python programming language. Program 1 Python Code list1 = ['physics', 'chemistry', 1997, 2000] list2 = [1, 2, 3, 4, 5, 6, 7 ] print &quot;list1[0]: &quot;, list1[0] #statement 1 print &qu
3 min read
Output of C programs | Set 30 (Switch Case)
Prerequisite - Switch Case in C/C++ Interesting Problems of Switch statement in C/C++ Program 1 #include <stdio.h> int main() { int num = 2; switch (num + 2) { case 1: printf("Case 1: "); case 2: printf("Case 2: "); case 3: printf("Case 3: "); default: printf("Default: "); } return 0; } Output: Default:
2 min read
C++ Programming Multiple Choice Questions
C++ is the most used and most popular programming language developed by Bjarne Stroustrup. C++ is a high-level and object-oriented programming language. This language allows developers to code clean and efficient code for large applications and software like software/Application development, game development, and operating system programming. In th
1 min read
Output of Java Programs | Set 12
1) What is the output of the following program? Java Code public class Test implements Runnable { public void run() { System.out.printf("%d", 3); } public static void main(String[] args) throws InterruptedException { Thread thread = new Thread(new Test()); thread.start(); System.out.printf("%d", 1); thread.join(); System.out.pri
5 min read
Output of python program | Set 2
Difficulty level : IntermediatePredict the output of following Python Programs. Program 1: C/C++ Code class Acc: def __init__(self, id): self.id = id id = 555 acc = Acc(111) print (acc.id) Output: 111 Explanation: Instantiation of the class "Acc" automatically calls the method __init__ and passes the object as the self parameter. 111 is assigned to
2 min read
Output of Python Program | Set 1
Predict the output of following python programs: Program 1: [GFGTABS] Python r = lambda q: q * 2 s = lambda q: q * 3 x = 2 x = r(x) x = s(x) x = r(x) print (x) [/GFGTABS]Output: 24Explanation : In the above program r and s are lambda functions or anonymous functions and q is the argument to both of the functions. In first step we have initialized x
3 min read
Output of Java Program | Set 4
Predict the output of following Java Programs: Question 1 // file name: Main.java class Base { protected void foo() {} } class Derived extends Base { void foo() {} } public class Main { public static void main(String args[]) { Derived d = new Derived(); d.foo(); } } Output: Compiler Error foo() is protected in Base and default in Derived. Default a
2 min read
Output of Java Program | Set 3
Predict the output of the following Java Programs: Example1: Java Code // filename: Test.java class Test { // Declaring and initializing integer variable int x = 10; // Main driver method public static void main(String[] args) { // Creating an object of class inside main() Test t = new Test(); // Printing the value inside the object by // above cre
3 min read
Output of Java Program | Set 2
Predict the output of the following Java programs. Question 1: Java Code package main; class Base { public void Print() { System.out.println("Base"); } } class Derived extends Base { public void Print() { System.out.println("Derived"); } } class Main { public static void DoPrint(Base o) { o.Print(); } public static void main(Str
3 min read
Output of Java Program | Set 1
Difficulty Level: Rookie Predict the output of the following Java Programs.Program 1: Java Code // filename Main.java class Test { protected int x, y; } class Main { public static void main(String args[]) { Test t = new Test(); System.out.println(t.x + &quot; &quot; + t.y); } } Output: 0 0 In Java, a protected member is accessible in all cl
3 min read
Output of C++ Program | Set 5
Difficulty Level: RookiePredict the output of below C++ programs.Question 1 C/C++ Code #include<iostream> using namespace std; class Test { int value; public: Test(int v); }; Test::Test(int v) { value = v; } int main() { Test t[100]; return 0; } Output: Compiler error The class Test has one user defined constructor "Test(int v)" that expects
2 min read
Output of C++ Program | Set 4
Difficulty Level: Rookie Predict the output of below C++ programs. Question 1 #include<iostream> using namespace std; int x = 10; void fun() { int x = 2; { int x = 1; cout << ::x << endl; } } int main() { fun(); return 0; } Output: 10 If Scope Resolution Operator is placed before a variable name then the global variable is referen
2 min read
Output of C++ Program | Set 3
Predict the output of below C++ programs.Question 1 C/C++ Code #include<iostream> using namespace std; class P { public: void print() { cout <<" Inside P::"; } }; class Q : public P { public: void print() { cout <<" Inside Q"; } }; class R: public Q { }; int main(void) { R r; r.print(); return 0; } Output: Insi
2 min read
Output of C++ Program | Set 2
Predict the output of below C++ programs. Question 1 [GFGTABS] CPP #include <iostream> using namespace std; class A { public: A(int ii = 0): i(ii){} void show() { cout << "i = " << i << endl; } private: int i; }; class B { public: B(int xx): x(xx){} operator A() const { return A(x); } private: int x; }; void g(A a)
2 min read
Output of C++ Program | Set 1
Predict the output of below C++ programs. Question 1 // Assume that integers take 4 bytes. #include<iostream> using namespace std; class Test { static int i; int j; }; int Test::i; int main() { cout << sizeof(Test); return 0; } Output: 4 (size of integer) static data members do not contribute in size of an object. So 'i' is not consider
1 min read
Output of C Programs | Set 5
Predict the output of below programs Question 1 C/C++ Code int main() { while(1){ if(printf("%d",printf("%d"))) break; else continue; } return 0; } Output: Can't be predictedExplanation: The condition in while loop is 1 so at first shot it looks infinite loop. Then there are break and continue in the body of the while loop, so i
5 min read
Output of C Programs | Set 4
Predict the output of below programs Question 1 C/C++ Code #includeâ€đstdio.h‹ int main() { struct site { char name[] = &quot;GeeksforGeeks&quot;; int no_of_pages = 200; }; struct site *ptr; printf(&quot;%d&quot;,ptr-&gt;no_of_pages); printf(&quot;%s&quot;,ptr-&gt;name); getchar(); return 0; } Output: Compiler errorExp
2 min read
Output of C Programs | Set 3
Predict the output of the below program. Question 1 C/C++ Code #include <stdio.h> int main() { printf("%p", main); getchar(); return 0; } Output: Address of function main. Explanation: Name of the function is actually a pointer variable to the function and prints the address of the function. Symbol table is implemented like this. st
3 min read
Output of C Programs | Set 2
Predict the output of below programs. Question 1 C/C++ Code #include<stdio.h> char *getString() { char str[] = "Will I be printed?"; return str; } int main() { printf("%s", getString()); getchar(); } Output: Some garbage value The above program doesn't work because array variables are stored in Stack Section. So, when getS
2 min read
Output of C Programs | Set 1
Predict the output of below programs. Question 1 [GFGTABS] c #include<stdio.h> int main() { int n; for(n = 7; n!=0; n--) printf("n = %d", n--); getchar(); return 0; } [/GFGTABS]Output: Above program goes in infinite loop because n is never zero when loop condition (n != 0) is checked. Question 2 [GFGTABS] c #include<stdio.h> i
2 min read
Article Tags :