0% found this document useful (0 votes)
26 views

CS201 – Complete MCQs with Answers Updated Version

Sudent Guidess
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

CS201 – Complete MCQs with Answers Updated Version

Sudent Guidess
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 45

✅ CS201 – Complete 27 MCQs with Answers

No. Question Options Correct Answer


1 Which of the following is a valid a) 3data b) data-3 c) data_3 d) ✅ c) data_3
C++ identifier? class
2 What does ++a do in C++? a) Increments after use b) ✅ b) Increments
Increments before use before use
3 Which header is required to use a) stdio.h b) iostream c) ✅ b) iostream
cout and cin? conio.h d) string
4 What is the result of 5 / 2 in C+ a) 2.5 b) 3 c) 2 d) Error ✅ c) 2
+?
5 Which operator is used for input? a) << b) >> c) :: d) && ✅ b) >>
6 Which data type can store a) int b) float c) char d) bool ✅ b) float
decimal values?
7 Which of the following is a a) && b) ++ c) = d) % ✅ a) &&
logical operator?
8 A function that does not return a a) void b) int c) char d) return ✅ a) void
value is declared as:
9 What does cin >> a; mean in a) Output b) Input c) Function ✅ b) Input
C++? d) Header
10 What is the size of int on most a) 1 b) 2 c) 4 d) 8 ✅ c) 4
32-bit systems?
11 Which loop is guaranteed to run a) for b) while c) do-while d) ✅ c) do-while
at least once? none
12 Which keyword is used to define a) call b) define c) function d) ✅ d) return
a function? return
13 What does if (a == b) check? a) Assignment b) Equality c) ✅ b) Equality
Inequality d) Logical
14 The main() function returns a) void b) int c) bool d) float ✅ b) int
which data type by default?
15 Which of these is a relational a) && b) >= c) = d) ++ ✅ b) >=
operator?
16 The break statement is used to: a) Exit loop b) Pause program ✅ a) Exit loop
c) Return value
17 Which of the following is not a a) float b) number c) int d) ✅ b) number
valid data type in C++? bool
18 What does for(int i = 0; i < a) Infinite loop b) Error c) ✅ c) Loop from 0
5; i++) do? Loop from 0 to 4 to 4
19 Which of these is an assignment a) == b) = c) := d) => ✅ b) =
operator?
20 The expression a % b returns: a) Quotient b) Sum c) ✅ c) Remainder
Remainder d) Float
21 What is the purpose of the a) Print output b) Exit loop c) ✅ c) Exit function
return statement? Exit function
22 Which one is a correct function a) func x; b) void x(); c) int ✅ b) void x();
declaration? x{}; d) float(x);
23 Which loop is best when number a) while b) do-while c) for d) ✅ c) for
of iterations is known? goto
24 What is the purpose of the a) Return input b) Return size ✅ b) Return size of
sizeof() operator? of data data
25 A variable must be declared a) Use ✅ b) Compilation c) ✅ a) Use
before: Output d) Return
26 Which of the following stores a a) int b) float c) bool d) char ✅ d) char
single character?
27 A while loop stops when: a) Condition is true b) ✅ b) Condition is
Condition is false ✅ false

🎯 MCQs from Lectures 01–18:

1. Which of the following is a valid C++ identifier?


a) 3data
b) data_3 ✅
c) data-3
d) class
2. What is the output of the following code?

cpp
CopyEdit
int a = 5;
cout << ++a;

a) 5
b) 6 ✅
c) Error
d) 4

3. Which of the following is a valid header file in C++?


a) stdio.h
b) conio.h
c) iostream ✅
d) streamio
4. Which operator is used for input in C++?
a) >> ✅
b) <<
c) ::
d) &&
5. Which loop is guaranteed to execute at least once?
a) for
b) while
c) do-while ✅
d) nested for
6. Function that doesn’t return any value must be declared as:
a) int
b) void ✅
c) float
d) return
7. In C++, '==' is:
a) Assignment operator
b) Relational operator ✅
c) Logical operator
d) Bitwise operator
8. What will sizeof(int) return on most systems?
a) 1
b) 2
c) 4 ✅
d) 8

✍️Section B: Subjective (Total 16 Marks)

🔹 Part 1: 3-Marks Questions (Attempt 2 out of 3)


Q1. Define the difference between while and do-while loop. ✅
Answer:

 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.

Q3. What is the purpose of return statement in a function?


Answer:

 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)

Q1. Write a function in C++ to find the square of a number. ✅


Answer:

cpp
CopyEdit
#include<iostream>
using namespace std;

int square(int num) {


return num * num;
}

int main() {
int x = 5;
cout << "Square: " << square(x);
return 0;
}

Q2. Explain the types of loops in C++ with example.


Answer:
C++ has 3 types of loops:

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;
}

📘 CS201 Lecture-wise Notes & MCQs (Lectures 1–18)

Lecture 1: Introduction to Programming

Key Concepts:

 Definition and importance of programming


 Problem-solving steps in programming
 Introduction to algorithms and flowcharts

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

Lecture 2: First Program Overview

Key Concepts:

 Structure of a C++ program


 main() function
 Input/output using cin and cout

Sample MCQs:

1. Which header file is required for cin and cout?


o A) <stdio.h>
o B) <iostream> ✅
o C) <conio.h>
o D) <stdlib.h>
2. What is the correct syntax to output "Hello World" in C++?
o A) printf("Hello World");
o B) cout << "Hello World"; ✅
o C) print("Hello World");
o D) echo "Hello World";

Source: Studocu - CS201 Lecture 2 Notes

Lecture 3: Variables and Data Types

Key Concepts:

 Declaration and initialization of variables


 Data types: int, float, char, bool
 Type conversion and casting

Sample MCQs:

1. Which of the following is a valid variable declaration in C++?


o A) int 1number;
o B) float number; ✅
o C) char;
o D) bool = true;
2. What is the size of a char data type in C++?
o A) 2 bytes
o B) 4 bytes
o C) 1 byte ✅
o D) 8 bytes

Source: YouTube - CS201 Lecture 3 MCQs

Lecture 4: Operators in C++

Key Concepts:

 Arithmetic operators: +, -, *, /, %
 Relational operators: ==, !=, <, >, <=, >=
 Logical operators: &&, ||, !

Sample MCQs:

1. Which operator is used to find the remainder in C++?


o A) /
o B) % ✅
o C) *
o D) //
2. What is the result of 5 > 3 && 2 < 4?
o A) true ✅
o B) false
o C) 0
o D) 1

Source: YouTube - CS201 Lecture 4 MCQs

Lecture 5: Conditional Statements

Key Concepts:

 if, else if, and else statements


 Nested if statements
 switch statement

Sample MCQs:

1. Which statement is used for multiple conditions in C++?


o A) if
o B) else
o C) switch ✅
o D) goto
2. What will be the output of the following code?
cpp
CopyEdit
int x = 10;
if (x > 5)
cout << "Greater";
else
cout << "Smaller";

o A) Greater ✅
o B) Smaller
o C) Error
o D) Nothing

Source: YouTube - CS201 Lecture 5 MCQs

📘 CS201 Lecture-wise Notes & MCQs (Lectures 6–18)

Lecture 6: Loops – Part 1

Key Concepts:

 Introduction to loops
 while loop syntax and flow
 Loop control variables
 Infinite loops and their prevention

Sample MCQs:

1. What is the primary use of a loop in programming?


o A) To store data
o B) To execute a block of code multiple times ✅
o C) To define functions
o D) To declare variables
2. Which loop checks the condition before executing the loop body?
o A) do-while
o B) for
o C) while ✅
o D) switch

Lecture 7: Loops – Part 2

Key Concepts:
 do-while loop syntax and flow
 Differences between while and do-while loops
 Use cases for do-while loops

Sample MCQs:

1. Which loop guarantees at least one execution of the loop body?


o A) for
o B) while
o C) do-while ✅
o D) if
2. What is the correct syntax for a do-while loop?
o A) do { } while(condition); ✅
o B) while(condition) { }
o C) for(initialization; condition; increment) { }
o D) if(condition) { }

Lecture 8: Loops – Part 3

Key Concepts:

 for loop syntax and flow


 Nested loops
 Loop control statements: break and continue

Sample MCQs:

1. Which loop is best suited when the number of iterations is known?


o A) while
o B) do-while
o C) for ✅
o D) switch
2. What does the continue statement do in a loop?
o A) Exits the loop
o B) Skips the current iteration and continues with the next ✅
o C) Stops the program
o D) None of the above

Lecture 9: Functions – Part 1

Key Concepts:

 Introduction to functions
 Function declaration and definition
 Calling functions
 Return types and parameters

Sample MCQs:

1. What is the purpose of a function in programming?


o A) To store data
o B) To perform a specific task and possibly return a value ✅
o C) To define variables
o D) To create loops
2. Which keyword is used to define a function that does not return a value?
o A) int
o B) float
o C) void ✅
o D) char

Lecture 10: Functions – Part 2

Key Concepts:

 Function overloading
 Default arguments
 Recursion basics

Sample MCQs:

1. What is function overloading?


o A) Defining multiple functions with the same name but different parameters ✅
o B) Defining functions inside loops
o C) Using too many functions
o D) None of the above
2. Which function calls itself during its execution?
o A) Overloaded function
o B) Recursive function ✅
o C) Inline function
o D) None of the above

Lecture 11: Arrays – Part 1

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

Lecture 12: Arrays – Part 2

Key Concepts:

 Multidimensional arrays
 Passing arrays to functions
 Array manipulation techniques

Sample MCQs:

1. How do you declare a two-dimensional array in C++?


o A) int arr[ ][ ];
o B) int arr[3][4]; ✅
o C) int arr(3,4);
o D) int arr{3,4};
2. Which of the following correctly passes an array to a function?
o A) function(arr); ✅
o B) function(&arr);
o C) function(*arr);
o D) function(arr[]);

Lecture 13: Strings

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;

Lecture 14: Structures

Key Concepts:

 Defining structures
 Accessing structure members
 Nested structures

Sample MCQs:

1. What is a structure in C++?


o A) A built-in data type
o B) A user-defined data type that groups related variables ✅
o C) A function
o D) None of the above
2. How do you access a member age of a structure variable person?
o A) person->age;
o B) person.age; ✅
o C) person:age;
o D) person(age);

Lecture 15: Pointers – Part 1

Key Concepts:

 Introduction to pointers
 Pointer declaration and initialization
 Dereferencing pointers

Sample MCQs:

1. What does a pointer store?


o A) A value
o B) An address of a variable ✅
o C) A function
o D) None of the above
2. Which operator is used to access the value at the address stored in a pointer?
o A) &
o B) * ✅
o C) ->
o D) %

Lecture 16: Pointers – Part 2

Key Concepts:

 Pointer arithmetic
 Pointers and arrays
 Pointers to functions

Sample MCQs:

1. What is the result of incrementing a pointer?


o A) Moves to the next memory location based on the data type size ✅
o B) Adds one to the value pointed by the pointer
o C) Decreases the address by one
o D) None of the above
2. How do you declare a pointer to a function?
o A) int *func();
o B) int (*func)(); ✅
o C) int func*();
o D) int func();

Lecture 17: File Handling – Part 1

Key Concepts:

 Introduction to file streams


 Opening and closing files
 Reading from and writing to files

Sample MCQs:

1. Which header file is required for file handling in C++?


o A) <fstream> ✅
o B) <iostream>
o C) <stdio.h>
D) <stdlib.h>
o
2. Which class is used to write to files in C++?
o A) ifstream
o B) ofstream ✅
o C) fstream
o D) file

Lecture 18: File Handling – Part 2

Key Concepts:

 File modes
 Checking file existence
 Error handling in file operations

Sample MCQs:

1. Which function is used to check if a file has been opened successfully?


o A) is_open() ✅
o B) open()
o C) eof()
o D) fail()
2. What does the ios::app mode do when opening a file?
o A) Opens the file for reading
o B) Opens the file for writing at the beginning
o C) Opens the file for appending at the end ✅
o D) Opens the file in binary mode

Question No: 1 (Marks: 01) - Please choose the correct option


…………. function is used to determine the current location while reading a file.

A. tellp()
B. tellg() ✔️
C. seekp()
D. seekg()

Question No: 2 (Marks: 01) - Please choose the correct option


…………. operator can be used for masking of flags.
A. ^ ✔️
B. &&
C. ||
D. >>

Question No: 3 (Marks: 01) - Please choose the correct option


What will be the output of the following code?

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

Question No: 4 (Marks: 01) - Please choose the correct option


What will be the output of the following code?

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

Question No: 6 (Marks: 01) - Please choose the correct option


In C++, “getline()” function is a built-in function that allows accepting and reading.

A. Single line
B. Multiple lines
C. Single and Multiple lines
D. Only multiword input ✔️

Question No: 7 (Marks: 01) - Please choose the correct option


Which one of the following is correct definition of structure?

A. struct Student{char name[30]}


B. struct Student {char name[30];} ✔️
C. struct Student {char name[35];};
D. struct {char name[30]};

Question No: 8 (Marks: 01) - Please choose the correct option


From the above code the correct way to access the data member title of the structure book through
pointer is?

A. sptr.title
B. sptr:title
C. sptr->title ✔️
D. .sptr*title

Question No: 9 (Marks: 01) - Please choose the correct option


What will be the output of the following program?

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

Question No: 10 (Marks: 01) - Please choose the correct option


The proper way of defining a macro is.

A. #define SIZE 5;
B. #define SIZE 5 ✔️
C. Set SIZE 5;
D. #set SIZE 5

Question No: 11 (Marks: 01) - Please choose the correct option


In C++, dynamic memory allocation is done on _____ memory.

A. Static
B. Stack
C. Heap ✔️
D. Hard Disk

Question No: 12 (Marks: 01) - Please choose the correct option


Which of the following is not an acceptable class specifier?

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

Question No: 14 (Marks: 01) - Please choose the correct option


In C++, class data members are generally kept as ______.

A. public
B. private ✔️
C. protected
D. static

Question No: 15 (Marks: 01) - Please choose the correct option


To declare the friend function, which keyword is used?

A. Friend
B. FRIEND
C. FrienD
D. friend ✔️

Question No: 16 (Marks: 01) - Please choose the correct option


In C++, which of the following operator cannot be overloaded?

A. +
B. -
C. /
D. -> ✔️

Question No: 17 (Marks: 01) - Please choose the correct option


A class includes both data members as well as functions to manipulate the data. These functions are
called ___________.
A. Member functions ✔️
B. Constant functions
C. Rational functions
D. Memory functions

Question No: 18 (Marks: 01) - Please choose the correct option


Which of the following is known as an instance of a class?

A. Data member
B. Constructor
C. Member function
D. Object ✔️

Question No: 19 (Marks: 01) - Please choose the correct option


In friend function, which operator is utilized to access members of a class using class objects.

A. ::
B. +
C. *
D. . ✔️

Question No: 20 (Marks: 01) - Please choose the correct option


Which of the following is the correct way of referring a data member “buf” of a class name “String”?
Consider “buf” data member declared as a character pointer.

A. buf;
B. this->buf; ✔️
C. *(this).buf;
D. *this.buf

Question No: 21 (Marks: 01) - Please choose the correct option


In C++, which of the following operator can be overloaded?

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

Question No: 23 (Marks: 01) - Please choose the correct option


What will be the output of following program in C++?

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

Question No: 24 (Marks: 01) - Please choose the correct option


Which of the following manipulators “Terminate a string with NULL”?

A. endl
B. flush
C. ends ✔️
D. ws

Question No: 25 (Marks: 01) - Please choose the correct option


What will be the output of following code snippet written in C++?

cpp
CopyEdit
int main(){
double var = 3.14362987;
cout<< setprecision(4) << var;
}

A. 3.144 ✔️
B. 3.143
C. 3.1436
D. 3.145

Question No: 26 (Marks: 01) - Please choose the correct option


Which of the following is not a format state flag?

A. ios::dec
B. ios::showpoint
C. ios::showcause ✔️
D. ios::right

Question No: 27 (Marks: 01) - Please choose the correct option


Which of the following is not a recommended way to use a copy constructor?

A. Explicit call to the copy constructor ✔️


B. Using “=” operator
C. In passing by value
D. In passing by reference

Question No: 28 (Marks: 01) - Please choose the correct option


If we press the key 1 from the keyboard to store it in integer i, the digit 1 travels as a(an) _________ but
stored as number inside i.
A. integer
B. character ✔️
C. float
D. double

Question No: 29 (Marks: 01) - Please choose the correct option


In C++, for every stream, there should be ________.

A. Template and class


B. Source and destination ✔️
C. Function and operator
D. Structure and Union

Question No: 30 (Marks: 01) - Please choose the correct option


In C++, whenever have an “&” ampersand symbol appears on right hand side of an “=” assignment
operator, it is taken as ______ of an object.

A. Pointer
B. Reference ✔️
C. Address
D. Function

Question No: 31 (Marks: 01) - Please choose the correct option


While writing nested classes in C++, no memory is allocated for it unless a/an _______ of it is created.

A. Function
B. Instance ✔️
C. Class
D. Operator

Question No: 32 (Marks: 01) - Please choose the correct option


In C++, which one from the following errors can be encountered when dealing with references.

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:

(Marks: 01) - Please choose the correct option


Which of the following is the correct way of calling a function?

A. function;
B. function();
C. function( ); ✔️
D. function[]

Question No: 34 (Marks: 01) - Please choose the correct option


Which of the following is the proper way of commenting a single line in C++?

A. /* comments */
B. // comments ✔️
C. ! comments
D. # comments

Question No: 35 (Marks: 01) - Please choose the correct option


Which of the following is the proper way of commenting multiple lines in C++?

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.

37. Trace the output of the following code segment:

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

38. What will be the output of the given code segment?

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.)

39. What will be the output of the given code segment?

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.

Question No: 41 (Marks: 03)

Determine the number of iterations the following loop will run.

int op, lim, k;


op = 6;
lim = 0;
while (k <= 60) {
k = op << lim;
lim += 1;
}

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.

Let’s compute each iteration manually:

Iteration lim k = 6 << lim = 6 * 2^lim Condition k <= 60


1 0 6 × 2⁰ = 6 ✅ Yes

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

✅ Final Answer: 4 iterations


✅ Question No: 42 (Marks: 03)

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;

🧠 Explanation of Masking Operator:

In C/C++, masking usually refers to using the bitwise AND (&) operator to filter specific bits in a value.

It is commonly used to isolate, clear, or toggle specific bits in an integer.

🧾 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

✅ Question No: 44 (Marks: 03)


Name the types of constructor used in C++.

✅ Types of Constructors in C++ (Short Answer):

1. Default Constructor – No parameters.


2. Parameterized Constructor – Takes arguments.
3. Copy Constructor – Creates a copy of another object.

Optional (if needed for explanation):


4. Move Constructor – Transfers resources (C++11+).
5. Constructor with Default Arguments – Acts as both default/parameterized.

✅ Question No: 45 (Marks: 03)

Write the keywords used for auxiliary input/output stream and printer output stream in DOS.

✅ Answer (Short):

 Auxiliary input/output stream: aux


 Printer output stream: prn

These are reserved device names in DOS for auxiliary device (usually serial port) and printer output
respectively.

✅ Question No: 49 (Marks: 05)

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];

// Use the array...

// Deleting the dynamic array to free memory


delete[] arr;

 new operator allocates memory for an array dynamically.


 delete[] operator frees the allocated memory of the array.

CS201 – Introduction to Programming

Complete 200 MCQs (Lectures 1–18)

Lectures 01–02: Intro to Programming, Flowcharts, Algorithms, Compilers (15


MCQs)

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

9. Which of the following is NOT a flowchart symbol?


a) Oval
b) Square ✓ ✔
c) Parallelogram
d) Diamond
10. What is the main function of linker?
a) Convert code
b) Link object files ✓ ✔
c) Debug code
d) Create flowchart
11. Which of the following is a low-level language?
a) C++
b) Java
c) Assembly ✓ ✔
d) Python
12. Which step comes last in programming?
a) Writing code
b) Debugging
c) Testing ✓ ✔
d) Designing algorithm
13. Which part of a program controls input?
a) cin ✓ ✔
b) cout
c) return
d) void
14. What does "syntax error" mean?
a) Logical error
b) Code does not follow language rules ✓ ✔
c) Runtime failure
d) Memory overflow
15. What does the term "runtime" refer to?
a) Time taken to compile
b) Time program is running ✓ ✔
c) Time to write code
d) Time to debug

Lectures 03–04: C++ Structure, Header Files, main(), cin/cout (15 MCQs)

16. Which header file is required for cout?


a) <iostream> ✓ ✔
b) <stdio.h>
c) <math.h>
d) <conio.h>
17. What is the correct return type of main()?
a) void
b) int ✓ ✔
c) float
d) char
18. How do you print “Hello World” in C++?
a) cout << "Hello World"; ✓ ✔
b) print("Hello World");
c) printf("Hello World");
d) System.out.println("Hello World");
19. Which operator is used to insert data into cout?
a) >>
b) << ✓ ✔
c) ||
d) &&
20. How do you take input in C++?
a) scanf()
b) cin >> variable; ✓ ✔
c) input()
d) read()
21. What does ‘return 0;’ indicate in main()?
a) Error occurred
b) Program executed successfully ✓ ✔
c) Function ended with failure
d) Infinite loop
22. Which is NOT a valid function header in C++?
a) int main()
b) void main()
c) main() ✓ ✔
d) int func()
23. How do you include a header file in C++?
a) #include <filename> ✓ ✔
b) import <filename>
c) include <filename>
d) #import <filename>
24. Which symbol is used to write comments in C++?
a) // ✓ ✔
b) <!-- -->
c) ##
d) $$
25. Which namespace is required to use cout without std::?
a) std ✓ ✔
b) cout
c) io
d) system
26. What will the following code output?

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

Lectures 05–06: Data Types, Variables, Constants, Comments (15 MCQs)

31. Which data type stores whole numbers?


a) float
b) int ✓ ✔
c) char
d) double
32. Which data type stores characters?
a) char ✓ ✔
b) int
c) float
d) bool
33. What keyword declares a constant variable?
a) const ✓ ✔
b) static
c) constant
d) final
34. What is the size of a char variable?
a) 1 byte ✓ ✔
b) 2 bytes
c) 4 bytes
d) 8 bytes
35. Which of these is a valid variable name?
a) 2name
b) name_1 ✓ ✔
c) @name
d) #name
36. Which keyword is used to define a boolean variable?
a) bool ✓ ✔
b) boolean
c) logical
d) bin
37. What is the default value of an uninitialized int variable?
a) 0
b) Garbage value ✓ ✔
c) Null
d) 1
38. How do you write a single-line comment?
a) // comment ✓ ✔
b) /* comment */
c) <!-- comment -->
d) # comment
39. What is the value of the expression: 5 / 2 in C++ if both operands are integers?
a) 2.5
b) 2 ✓ ✔
c) 3
d) 0
40. Which of these is a floating-point type?
a) int
b) float ✓ ✔
c) char
d) bool
41. Which of the following is NOT a valid C++ data type?
a) int
b) double
c) string ✓ ✔
d) char
42. How do you declare a variable of type integer named count?
a) int count; ✓ ✔
b) integer count;
c) var count;
d) count int;
43. What keyword is used to declare a variable that cannot be changed?
a) immutable
b) const ✓ ✔
c) final
d) static
44. Which of the following is a valid way to assign a value to a variable?
a) int x = 5; ✓ ✔
b) int x == 5;
c) int x := 5;
d) int x => 5;
45. Which data type would be most suitable to store 'true' or 'false'?
a) int
b) bool ✓ ✔
c) char
d) float

Lectures 07–08: Arithmetic, Logical, Relational Operators (15 MCQs)

46. Which operator is used for logical AND?


a) &
b) && ✓ ✔
c) ||
d) |
47. Which operator is used to compare equality?
a) =
b) == ✓ ✔
c) !=
d) <>
48. What will be the output of cout << (5 > 3);?
a) 0
b) 1 ✓ ✔
c) true
d) false
49. Which operator is used for logical OR?
a) &&
b) || ✓ ✔
c) !
d) &
50. What is the value of 10 % 3?
a) 1 ✓ ✔
b) 3
c) 0
d) 4
51. What does the ‘!’ operator do?
a) AND
b) OR
c) NOT ✓ ✔
d) XOR
52. Which operator is used for multiplication?
a) * ✓ ✔
b) x
c) %
d) /
53. Which of the following is NOT a relational operator?
a) <=
b) >=
c) =! ✓ ✔
d) !=
54. Which operator is used for addition?
a) + ✓ ✔
b) -
c) *
d) /
55. What will the expression !(false) evaluate to?
a) true ✓ ✔
b) false
c) 0
d) 1
56. Which operator has the highest precedence?
a) +
b) * ✓ ✔
c) -
d) /
57. What is the result of 7 / 2 in integer division?
a) 3 ✓ ✔
b) 3.5
c) 4
d) 2
58. Which operator is used to check if two values are NOT equal?
a) =!
b) != ✓ ✔
c) <>
d) !==
59. Which is a bitwise operator?
a) &&
b) ||
c) & ✓ ✔
d) !
60. What is the output of cout << (5 && 0);?
a) 5
b) 0 ✓ ✔
c) 1
d) Error

Lectures 09–10: Conditional Statements (if, if-else, switch) (15 MCQs)

61. Which of the following is the correct syntax of if statement?


a) if (x > y) {} ✓ ✔
b) if x > y {}
c) if x > y then {}
d) if (x > y);
62. Which keyword is used with if to execute alternative code?
a) else ✓ ✔
b) elseif
c) otherwise
d) then
63. What does the switch statement evaluate?
a) Variables
b) Expressions ✓ ✔
c) Functions
d) Loops
64. Which data type is used in switch expression?
a) int, char ✓ ✔
b) float
c) double
d) bool
65. What happens if no break is used in a switch case?
a) Error

4.1-mini
translate

Bilingual

Translation only

Hide translation

ChatGPT said:

b) Next cases execute (fall-through) ✓ ✔


c) Switch ends
d) Default case executes

66. Which of the following is correct syntax for switch?


a) switch (variable) { case 1: … break; } ✓ ✔
b) switch variable { case 1: … }
c) switch { case 1: … }
d) switch (variable) case 1: …
67. Which is NOT a valid if statement?
a) if (a == b) {}
b) if a == b {} ✓ ✔
c) if (a > b) {}
d) if (a != b) {}
68. How many else if statements can follow an if?
a) 1
b) 2
c) Unlimited ✓ ✔
d) 0
69. What is the purpose of default in switch?
a) Execute if no case matches ✓ ✔
b) End switch
c) Start switch
d) Compile error
70. What will be the output of this code?

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

74. Which statement is true?


a) else can appear without if
b) else must always be preceded by if ✓ ✔
c) else ends the program
d) else is optional keyword
75. What is the output of this switch?

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

Lectures 11–12: Loops (for, while, do-while) (15 MCQs)

76. Which loop executes at least once?


a) for
b) while
c) do-while ✓ ✔
d) none
77. What is the syntax for for-loop?
a) for (init; condition; increment) ✓ ✔
b) for (condition)
c) while (init; condition; increment)
d) for (init, condition, increment)
78. Which loop checks condition before executing?
a) do-while
b) while ✓ ✔
c) for
d) none
79. What is the output of this code?

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

80. Which statement breaks the loop?


a) break ✓ ✔
b) stop
c) exit
d) return
81. Which statement skips current iteration?
a) continue ✓ ✔
b) break
c) skip
d) pass
82. How many times will this loop run?

cpp
CopyEdit
int i=0;
while(i<5) {
i++;
}

a) 4
b) 5 ✓ ✔
c) Infinite
d) 0

83. Can a for loop be infinite?


a) Yes ✓ ✔
b) No
c) Only while can
d) Only do-while can
84. What is the output?

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

85. Which of these is NOT a loop?


a) for
b) while
c) do-while
d) if ✓ ✔
86. What happens if break is used inside nested loops?
a) Breaks all loops
b) Breaks innermost loop ✓ ✔
c) Breaks outer loop
d) Error
87. Which loop is preferred when number of iterations is known?
a) while
b) for ✓ ✔
c) do-while
d) none
88. What will be output of this code?

cpp
CopyEdit
for(int i=0; i<3; i++) {
if(i == 1) continue;
cout << i;
}

a) 012
b) 02 ✓ ✔
c) 01
d) 12

89. Which statement is true?


a) while loop always executes once
b) do-while executes at least once ✓ ✔
c) for loop never executes
d) None
90. What is the output?

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

Lectures 13–14: Functions, Parameters, Return Types (15 MCQs)

91. What keyword defines a function?


a) func
b) function
c) void ✓ ✔
d) define
92. Which is a valid function declaration?
a) int add(int a, int b); ✓ ✔
b) add(int a, int b);
c) int add a, b;
d) function add(int a, int b);
93. What is return type of void function?
a) int
b) nothing ✓ ✔
c) float
d) char
94. How do you call a function named sum()?
a) call sum();
b) sum(); ✓ ✔
c) function sum();
d) run sum();
95. What does the return statement do?
a) Exits program
b) Returns value from function ✓ ✔
c) Starts function
d) None
96. Can a function have more than one return statement?
a) Yes ✓ ✔
b) No
c) Only in main
d) Only void functions
97. What happens if no return statement in non-void function?
a) Returns 0
b) Returns garbage ✓ ✔
c) Compilation error
d) Runtime error
98. Which keyword is used to pass parameters by reference?
a) & ✓ ✔
b) *
c) ref
d) pointer
99. What is the default return type if none specified in C++?
a) void
b) int ✓ ✔
c) float
d) none
100. Which of the following is NOT a valid parameter?
a) int a
b) float b
c) sum c
d) char d ✓ ✔
101. Which function call is correct?
a) add(5, 10); ✓ ✔
b) add(5)
c) add()
d) add(5, "10")
102. What is function overloading?
a) Same function name, different parameters ✓ ✔
b) Multiple returns
c) Different return types
d) None
103. Can functions call other functions?
a) Yes ✓ ✔
b) No
c) Only main
d) Only void
104. What does parameter mean?
a) Variable passed to function ✓ ✔
b) Return type
c) Function name
d) Loop variable
105. Which keyword indicates a function does not return a value?
a) int
b) void ✓ ✔
c) return
d) null

Lectures 15–16: Arrays, Strings (15 MCQs)

106. How to declare an array of 5 integers?


a) int arr[5]; ✓ ✔
b) array int arr;
c) int arr();
d) int[5] arr;
107. How are array elements indexed?
a) From 1
b) From 0 ✓ ✔
c) From -1
d) From 5
108. What is the output?

cpp
CopyEdit
int arr[3] = {1, 2, 3};
cout << arr[1];

a) 1
b) 2 ✓ ✔
c) 3
d) Error

109. Which of the following is NOT true about arrays?


a) Fixed size
b) Contiguous memory
c) Can store different data types ✓ ✔
d) Indexed by integers
110. How to declare a string in C++?
a) string str; ✓ ✔
b) char str;
c) string[] str;
d) char str[];
111. How do you initialize a string?
a) string s = "Hello"; ✓ ✔
b) string s = 'Hello';
c) char s = "Hello";
d) char s = 'Hello';
112. What is the size of a string "abc"?
a) 2
b) 3 ✓ ✔
c) 4
d) Undefined
113. Which header is needed for string?
a) <string> ✓ ✔
b) <iostream>
c) <cstring>
d) <stdio.h>
114. How to access last element of an array arr with 5 elements?
a) arr[4]; ✓ ✔
b) arr[5];
c) arr[0];
d) arr[last];
115. Can arrays be resized after declaration?
a) Yes
b) No ✓ ✔
c) Sometimes
d) Depends on compiler
116. What is the default value of elements in an int array?
a) 0 ✓ ✔
b) Null
c) Garbage
d) 1
117. Which function gets length of a string?
a) size()
b) length() ✓ ✔
c) count()
d) strlen()
118. Can strings be modified?
a) Yes
b) No
c) Yes if mutable ✓ ✔
d) No if declared const
119. Which of these is NOT a string operation?
a) Concatenation
b) Comparison
c) Sorting ✓ ✔
d) Copying
120. How to declare a two-dimensional array?
a) int arr[2][3]; ✓ ✔
b) int arr(2,3);
c) int arr[2,3];
d) array arr[2][3];

Lectures 17–18: Pointers, References (10 MCQs)

121. What does a pointer store?


a) Value
b) Memory address ✓ ✔
c) Variable name
d) Function
122. How to declare a pointer to int?
a) int ptr; ✓ ✔
b) ptr int;
c) pointer int;
d) int ptr*;
123. How to get address of variable x?
a) &x ✓ ✔
b) *x
c) x&
d) @x
124. What does *ptr mean?
a) Address of ptr
b) Value pointed by ptr ✓ ✔
c) Pointer declaration
d) None
125. Which of the following is valid pointer initialization?
a) int *p = NULL; ✓ ✔
b) int *p = 5;
c) int *p = "Hello";
d) int *p;
126. How to declare a reference to variable x?
a) int &ref = x; ✓ ✔
b) int *ref = x;
c) int ref = &x;
d) int ref;
127. Which operator is used to dereference a pointer?
a) &
b) * ✓ ✔
c) %
d) $
128. What is the output?

cpp
CopyEdit
int x = 5;
int *p = &x;
cout << *p;

a) 5 ✓ ✔
b) Address
c) Error
d) Garbage

129. Which is true about references?


a) Can be reassigned
b) Must be initialized when declared ✓ ✔
c) Can be null
d) None
130. What happens if you dereference a null pointer?
a) Runtime error ✓ ✔
b) Returns 0
c) Returns garbage
d) Compile error

You might also like