CS201 – Complete MCQs with Answers Updated Version
CS201 – Complete MCQs with Answers Updated Version
cpp
CopyEdit
int a = 5;
cout << ++a;
a) 5
b) 6 ✅
c) Error
d) 4
while loop checks condition first; it may not execute even once.
do-while executes the block at least once, then checks the condition.
Q2. What is the difference between syntax error and logical error?
Answer:
Syntax Error: Error in code structure, e.g., missing semicolon. Detected by compiler.
Logical Error: Code runs, but output is incorrect due to wrong logic. Not detected by compiler.
It returns a value from the function to the calling code and ends function execution.
🔷 Part 2: 5-Marks Questions (Attempt 2 out of 3)
cpp
CopyEdit
#include<iostream>
using namespace std;
int main() {
int x = 5;
cout << "Square: " << square(x);
return 0;
}
1. for loop
cpp
CopyEdit
for(int i = 0; i < 5; i++) {
cout << i;
}
2. while loop
cpp
CopyEdit
int i = 0;
while(i < 5) {
cout << i;
i++;
}
3. do-while loop
cpp
CopyEdit
int i = 0;
do {
cout << i;
i++;
} while(i < 5);
Q3. Write a program that takes two numbers and prints the greater one. ✅
Answer:
cpp
CopyEdit
#include<iostream>
using namespace std;
int main() {
int a, b;
cout << "Enter two numbers: ";
cin >> a >> b;
if (a > b)
cout << a << " is greater";
else
cout << b << " is greater";
return 0;
}
Key Concepts:
Sample MCQs:
1. What is programming?
o A) A hobby
o B) A precise sequence of steps to solve a problem ✅
o C) A type of software
o D) An art form
2. Which skill is emphasized as crucial for programming?
o A) Memorization
o B) Paying attention to detail ✅
o C) Graphic design
o D) Networking
Source: Studocu - CS201 Lecture-wise MCQs
Key Concepts:
Sample MCQs:
Key Concepts:
Sample MCQs:
Key Concepts:
Arithmetic operators: +, -, *, /, %
Relational operators: ==, !=, <, >, <=, >=
Logical operators: &&, ||, !
Sample MCQs:
Key Concepts:
Sample MCQs:
o A) Greater ✅
o B) Smaller
o C) Error
o D) Nothing
Key Concepts:
Introduction to loops
while loop syntax and flow
Loop control variables
Infinite loops and their prevention
Sample MCQs:
Key Concepts:
do-while loop syntax and flow
Differences between while and do-while loops
Use cases for do-while loops
Sample MCQs:
Key Concepts:
Sample MCQs:
Key Concepts:
Introduction to functions
Function declaration and definition
Calling functions
Return types and parameters
Sample MCQs:
Key Concepts:
Function overloading
Default arguments
Recursion basics
Sample MCQs:
Key Concepts:
Introduction to arrays
Declaring and initializing arrays
Accessing array elements
Sample MCQs:
1. What is an array?
o A) A single variable
o B) A collection of variables of different types
o C) A collection of variables of the same type stored in contiguous memory locations ✅
o D) None of the above
2. How do you access the third element in an array named arr?
o A) arr[2] ✅
o B) arr(3)
o C) arr{3}
o D) arr.3
Key Concepts:
Multidimensional arrays
Passing arrays to functions
Array manipulation techniques
Sample MCQs:
Key Concepts:
Character arrays
String manipulation functions
Input/output of strings
Sample MCQs:
1. Which header file is required for string manipulation functions like strlen and strcpy?
o A) <iostream>
o B) <string.h> ✅
o C) <stdio.h>
o D) <stdlib.h>
2. What is the correct way to declare a string in C++?
o A) char str[] = "Hello"; ✅
o B) string str = 'Hello';
o C) char str = "Hello";
o D) char str = Hello;
Key Concepts:
Defining structures
Accessing structure members
Nested structures
Sample MCQs:
Key Concepts:
Introduction to pointers
Pointer declaration and initialization
Dereferencing pointers
Sample MCQs:
Key Concepts:
Pointer arithmetic
Pointers and arrays
Pointers to functions
Sample MCQs:
Key Concepts:
Sample MCQs:
Key Concepts:
File modes
Checking file existence
Error handling in file operations
Sample MCQs:
A. tellp()
B. tellg() ✔️
C. seekp()
D. seekg()
cpp
CopyEdit
int main(){
int i = 20;
for(int i=1;i<10;i++);
cout<<i;
return 0;
}
A. 10
B. 20 ✔️
C. 9
D. 1
cpp
CopyEdit
int main() {
change();
return 0;
}
int change (int a=12){
int b=12;
a = a + b;
cout<<a++;
}
A. 12
B. 24
C. 25 ✔️
D. 26
Question No: 5 (Marks: 01) - Please choose the correct option
While handling files in C++, the default mode of “ifstream” library for opening file is.
A. ios::ate
B. ios::out
C. ios::in ✔️
D. ios::app
A. Single line
B. Multiple lines
C. Single and Multiple lines
D. Only multiword input ✔️
A. sptr.title
B. sptr:title
C. sptr->title ✔️
D. .sptr*title
cpp
CopyEdit
#include <iostream>
#define LIMIT 3
int main()
{
for (int i = 2; i < LIMIT; i++) {
std::cout << i* LIMIT << "\t";
}
return 0;
}
A. 6 ✔️
B. 2 3 6
C. 3
D. 9
A. #define SIZE 5;
B. #define SIZE 5 ✔️
C. Set SIZE 5;
D. #set SIZE 5
A. Static
B. Stack
C. Heap ✔️
D. Hard Disk
A. public
B. private
C. protected
D. pointer ✔️
Question No: 13 (Marks: 01) - Please choose the correct option
_____ is another name for a class's data members.
A. Attribute ✔️
B. Method
C. Instance
D. Dimensions
A. public
B. private ✔️
C. protected
D. static
A. Friend
B. FRIEND
C. FrienD
D. friend ✔️
A. +
B. -
C. /
D. -> ✔️
A. Data member
B. Constructor
C. Member function
D. Object ✔️
A. ::
B. +
C. *
D. . ✔️
A. buf;
B. this->buf; ✔️
C. *(this).buf;
D. *this.buf
A. sizeof
B. ?:
C. ::
D. % ✔️
Question No: 22 (Marks: 01) - Please choose the correct option
When a unary operator is overloaded and is a member of a class, how many arguments need to be
passed explicitly when it is called?
A. Zero ✔️
B. One
C. Two
D. Three
cpp
CopyEdit
#include<iostream>
using namespace std;
class A
{
int a;
public:
A(int x):a(x){}
int geta() {return a;}
};
int main ()
{
A M(10),N(20);
N = M;
cout<<N.geta();
return 0;
}
A. 20
B. 10 ✔️
C. 30
D. 15
A. endl
B. flush
C. ends ✔️
D. ws
cpp
CopyEdit
int main(){
double var = 3.14362987;
cout<< setprecision(4) << var;
}
A. 3.144 ✔️
B. 3.143
C. 3.1436
D. 3.145
A. ios::dec
B. ios::showpoint
C. ios::showcause ✔️
D. ios::right
A. Pointer
B. Reference ✔️
C. Address
D. Function
A. Function
B. Instance ✔️
C. Class
D. Operator
A. Memory Leak
B. Dangling Reference ✔️
C. Static Reference
D. Global Reference
Question No: 33
4.1-mini
translate
Bilingual
Translation only
Hide translation
ChatGPT said:
A. function;
B. function();
C. function( ); ✔️
D. function[]
A. /* comments */
B. // comments ✔️
C. ! comments
D. # comments
A. / comments / ✔️
B. // comments
C. ! comments
D. # comments
36. In C/C++, the array index number for representing last element of an array of size 10 is
_____.
A. 5
B. 7
✔️C. 9
D. 11
👉 Explanation: Indexing starts from 0, so the last index of an array of size 10 is 9.
cpp
CopyEdit
int main(){
int arr[2][3]= {{1, 2, 3}, {4, 5, 6}};
cout<<arr[1][1];
}
A. 2
B. 4
✔️C. 5
D. 6
👉 Explanation: arr[1][1] accesses the second row, second column element = 5
cpp
CopyEdit
int arr[]={2,5,6,8,9,10,6,3,1};
int * ptr= &arr[1];
cout<<*(ptr+4);
A. 6
B. 10
✔️C. 3
D. 1
👉 Explanation: ptr = &arr[1] means pointer at value 5; *(ptr+4) = value at arr[5] = 10
(❗ But correct answer is C. 3, so either array or pointer value might be wrong in the question as
given. Please double-check the original exam content.)
cpp
CopyEdit
int arr[]={2,5,6,8,9,10,6,3,1};
int * ptr= &arr[3];
cout<<*(ptr+4);
A. 10
B. 6
✔️C. 3
D. 5
👉 Explanation: ptr = &arr[3] (value 8); *(ptr+4) = arr[7] = 3
40. Which one of the following is not a keyword and can be used as an identifier in C/C++?
✔️A. friends
B. template
C. this
D. new
👉 Explanation: friends is not a C++ keyword, but friend is. So friends can be used as an
identifier.
To solve Question No: 41, we need to determine how many iterations the loop will execute:
🔢 Given Code:
cpp
CopyEdit
int op, lim, k;
op = 6;
lim = 0;
while (k <= 60) {
k = op << lim;
lim += 1;
}
🧠 Step-by-step Explanation:
The expression op << lim means bitwise left shift, i.e., op * (2^lim).
So, we calculate how long the result k = op << lim stays ≤ 60.
2 1 6 × 2¹ = 12 ✅ Yes
3 2 6 × 2² = 24 ✅ Yes
4 3 6 × 2³ = 48 ✅ Yes
5 4 6 × 2⁴ = 96 ❌ No → loop exits
What is the masking operator? Write the code snippet and determine the output of expression which
masks a variable int x = 100; with int m = 50;
In C/C++, masking usually refers to using the bitwise AND (&) operator to filter specific bits in a value.
🧾 Code Snippet:
cpp
CopyEdit
#include <iostream>
using namespace std;
int main() {
int x = 100;
int m = 50;
int result = x & m;
cout << "Result: " << result;
return 0;
}
📌 Bitwise Breakdown:
yaml
CopyEdit
x = 100 → binary: 0110 0100
m = 50 → binary: 0011 0010
-----------------------------
x & m → 0010 0000 = 32
✅ Final Output: 32
Write the keywords used for auxiliary input/output stream and printer output stream in DOS.
✅ Answer (Short):
These are reserved device names in DOS for auxiliary device (usually serial port) and printer output
respectively.
Write the C++ syntax to create and delete a dynamic array using new and delete operator.
✅ Answer:
cpp
CopyEdit
// Creating a dynamic array of size n
int* arr = new int[n];
1. What is an algorithm?
a) A programming language
b) A step-by-step problem solving procedure ✓ ✔
c) A type of compiler
d) A flowchart symbol
2. Which symbol represents a decision in flowcharts?
a) Rectangle
b) Diamond ✓ ✔
c) Oval
d) Circle
3. What is the role of a compiler?
a) Convert source code to machine code ✓ ✔
b) Run code line-by-line
c) Store variables
d) Manage memory
4. Which language is high-level?
a) Assembly
b) C++ ✓ ✔
c) Binary
d) Machine code
5. What is the first step in programming?
a) Coding
b) Algorithm design ✓ ✔
c) Debugging
d) Compiling
6. What does IDE stand for?
a) Integrated Development Environment ✓ ✔
b) Internal Debug Environment
c) Interface Design Editor
d) Independent Data Editor
7. Which of these is NOT a programming language?
a) Python
b) Java
c) HTML ✓ ✔
d) C
8. What is the output of the following code?
cpp
CopyEdit
int main() {
std::cout << 5 + 2;
return 0;
}
a) 7 ✓ ✔
b) 52
c) 5 + 2
d) Error
Lectures 03–04: C++ Structure, Header Files, main(), cin/cout (15 MCQs)
cpp
CopyEdit
int a = 5;
int b = 10;
std::cout << a + b;
a) 15 ✓ ✔
b) 510
c) 5 + 10
d) Error
27. Which of the following is a correct way to start the main function?
a) int main() ✓ ✔
b) main int()
c) void main()
d) main()
28. What is the correct syntax to end a statement in C++?
a) .
b) ; ✓ ✔
c) :
d) ,
29. Which keyword is used to create a function?
a) func
b) function
c) void ✓ ✔
d) def
30. What is the use of cin?
a) Output text
b) Input data ✓ ✔
c) Pause program
d) Return value
4.1-mini
translate
Bilingual
Translation only
Hide translation
ChatGPT said:
cpp
CopyEdit
int x = 10;
if (x > 5) {
cout << "Yes";
} else {
cout << "No";
}
a) Yes ✓ ✔
b) No
c) Error
d) None
71. What is the correct way to write an if statement that checks if x is NOT equal to 10?
a) if (x != 10) ✓ ✔
b) if (x =! 10)
c) if (x = 10)
d) if (!x = 10)
72. Can the if statement execute without braces?
a) Yes, if single statement ✓ ✔
b) No
c) Only in C
d) Only with else
73. What is the output of the following?
cpp
CopyEdit
int a = 2;
if (a == 2)
cout << "Two";
else
cout << "Not Two";
a) Two ✓ ✔
b) Not Two
c) Error
d) Nothing
cpp
CopyEdit
int num = 3;
switch(num) {
case 1: cout << "One"; break;
case 2: cout << "Two"; break;
default: cout << "Default";
}
a) One
b) Two
c) Default ✓ ✔
d) Error
cpp
CopyEdit
for(int i=1; i<=3; i++) {
cout << i << " ";
}
a) 1 2 3 ✓ ✔
b) 0 1 2
c) 1 2 3 4
d) Error
cpp
CopyEdit
int i=0;
while(i<5) {
i++;
}
a) 4
b) 5 ✓ ✔
c) Infinite
d) 0
cpp
CopyEdit
int i=1;
do {
cout << i << " ";
i++;
} while(i<=3);
a) 1 2 3 ✓ ✔
b) 1 2
c) 2 3
d) 1 2 3 4
cpp
CopyEdit
for(int i=0; i<3; i++) {
if(i == 1) continue;
cout << i;
}
a) 012
b) 02 ✓ ✔
c) 01
d) 12
cpp
CopyEdit
int i=0;
while(i < 3) {
cout << i << " ";
i++;
}
a) 0 1 2 ✓ ✔
b) 1 2 3
c) 0 1 2 3
d) None
cpp
CopyEdit
int arr[3] = {1, 2, 3};
cout << arr[1];
a) 1
b) 2 ✓ ✔
c) 3
d) Error
cpp
CopyEdit
int x = 5;
int *p = &x;
cout << *p;
a) 5 ✓ ✔
b) Address
c) Error
d) Garbage