C and C++ Programming MCQ Set Important Questions for Beginners : Bikram Sutradhar
C and C++ Programming Multiple Choice Questions
C Programming and C++ Programming with Fundamentals set by Bikram Sutradhar
- What is the correct syntax to declare an array of integers with 10 elements in C?
a) int array[10];
b) int array(10);
c) array int[10];
d) int[10] array;
Answer: a) int array[10]; - Which of the following is the correct way to read a string from user input in C?
a) scanf(“%s”, str);
b) getline(str);
c) input(str);
d) read(str);
Answer: a) scanf(“%s”, str); - What will the following code print? int a=3,b=5;
printf(“%d”, a > b ? a : b); a) 3
b) 5
c) 0
d) 1
Answer: b) 5 - Which function is used to free dynamically allocated memory in C?
a) freeMemory();
b) release();
c) free();
d) deallocate();
Answer: c) free(); - What does the following code do? int x = 10;
int *ptr = &x;
*ptr = 20; a) Changes x to 10
b) Changes ptr to 20
c) Changes x to 20
d) Causes a segmentation fault
Answer: c) Changes x to 20
Section 2: C++ Programming
- In C++, what keyword is used to inherit a class?
a) extends
b) inherits
c) class
d) :
Answer: d) : - output of the C++ code? int arr[] = {1, 2, 3};
cout << arr[1]; a) 1
b) 2
c) 3
d) Compilation error
Answer: b) 2 - Which of the following correctly defines a destructor in C++?
a) ~ClassName();
b) ClassName();
c) destroy ClassName;
d) ClassName::~();
Answer: a) ~ClassName(); - What is the purpose of the const keyword in C++?
a) To declare a constant variable
b) To define a class
c) To create a pointer
d) To overload operators
Answer: a) To declare a constant variable - Which of the following is a feature of Object-Oriented Programming in C++?
a) Inheritance
b) Encapsulation
c) Polymorphism
d) All of the above
Answer: d) All of the above
Section 3: General Concepts
- Which of the following directives is used to include standard libraries in C/C++?
a) #library
b) #include
c) #define
d) #import
Answer: b) #include - What is the primary purpose of the main() function?
a) To define classes
b) To execute the program
c) To include libraries
d) To declare variables
Answer: b) To execute the program - In C/C++, which loop is guaranteed to execute at least once?
a) for loop
b) while loop
c) do-while loop
d) None of the above
Answer: c) do-while loop - Which operator is used for pointer dereferencing in C/C++?
a) &
b) *
c) ->
d) .
Answer: b) * - output of the code?
for (int i = 1; i <= 3; i++) {
cout << i;
}
a) 012
b) 123
c) 1234
d) 234
Answer: b) 123
Bikram Sutradhar Notes
Mastering C, C++, Java, and HTML: Your Ultimate Programming Questions Answered
C Programming and C++ Programming Mcq Question answer
Tripura board of secondary education Class 12 Education Important & Model Question Solution
Tripura board of secondary education Class 12 economics Important & Model Question Solution
Comprehensive Guide to the Digestive System: Selina Class 9 Biology Solutions Hindi & English