C
C
a) int
b) float
c) string
d) bool
Answer: c) string
3. Creation/Synthesis: Which keyword is used to create a new object from a class in C++?
a) new
b) create
c) object
d) instance
Answer: a) new
4. Psychomotor: Which operator is used to access a member of an object in C++?
a) .
b) :
c) ->
d) ::
Answer: a) .
6. Analysis: Which of the following loops is best suited for situations where the number of iterations is
known?
a) for loop
b) while loop
c) do-while loop
d) switch statement
a) <iostream>
b) <stdio.h>
c) <string>
d) <cmath>
Answer: a) <iostream>
a) const var_name;
b) constant var_name;
c) var_name const;
9. Understanding: What is the purpose of the return type in a function declaration in C++?
Answer: c) It specifies the data type of the value returned by the function.
b) +
c) *
d) %
Answer: a) +
11. Creation/Synthesis: Which of the following is a valid way to initialize an array in C++?
b) int arr[3];
a) ::
b) *
c) &
d) =
Answer: b) *
a) Terminates the current loop and transfers control to the next iteration
b)
Answer: a) Terminates the current loop and transfers control to the next iteration
15. Creation/Synthesis: Which of the following is not a valid way to pass arguments to a function in C++?
a) Pass by value
b) Pass by reference
c) Pass by pointer
d) Pass by class
b) fstream file("filename.txt");
c) ofstream file("filename.txt");
d) open("filename.txt", "w");
a) &&
b) ||
c) !
d) %
Answer: d) %
a) void functionName() {}
b) functionName() {}
c) functionName(void) {}
d) void functionName(void) {}
20. Psychomotor: How do you access the command-line arguments passed to a C++ program?
a) argc
b) argv[]
c) argv
d) argc[]
Answer: b) argv[]
21. Understanding: Which of the following is not a valid way to create a C++ class?
22. Analysis: Which header file should be included to use mathematical functions like sqrt() and pow() in
C++?
a) <math.h>
b) <cmath>
c) <iostream>
d) <fstream>
Answer: b) <cmath>
a) pointerType var_name;
b) var_name pointerType;
c) pointerType *var_name;
d) *pointerType var_name;
24. Psychomotor: Which operator is used to increment the value of a variable by 1 in C++?
a) ++
b) --
c) +=
d) *=
Answer: a) ++
Answer
a) ++
b) --
c) +=
d) *=
Answer: b) --
27. Creation/Synthesis: How do you define a constant member function in a C++ class?
b) functionName() const {}
a) delete
b) free
c) deallocate
d) clear
Answer: a) delete
c) It specifies the alternative block of code to execute if the condition of an "if" statement is false
Answer: c) It specifies the alternative block of code to execute if the condition of an "if" statement is
false
30. Analysis: Which of the following is not a type of function overloading in C++?
a) Operator overloading
b) Constructor overloading
d) Method overloading
Certainly! Here are 30 multiple-choice questions related to a program that utilizes structures, arrays,
functions, and pointers. Each question is followed by its answer:
1. Application: Which programming construct is used to group related data items into a single entity in
C++?
a) Arrays
b) Pointers
c) Structures
d) Functions
Answer: c) Structures
a) struct myStruct {}
b) class myStruct {}
4. Application: Which programming construct allows you to pass a structure as a parameter to a function
in C++?
a) Arrays
b) Pointers
c) Structures
d) Functions
Answer: c) Structures
6. Creation/Synthesis: Which of the following is the correct way to declare a function prototype in C++?
a) returnType functionName(parameters);
b) functionName(parameters) returnType;
d) functionName(parameters);
7. Application: Which programming construct is used to store the address of a variable in C++?
a) Arrays
b) Pointers
c) Structures
d) Functions
Answer: b) Pointers
c) It is used to access and modify the value stored at a specific memory address.
Answer: c) It is used to access and modify the value stored at a specific memory address.
a) int ptr;
b) ptr int;
c) int *ptr;
d) *int ptr;
10. Application: How can you access the members of a structure variable in C++?
11. Evaluation: What is the purpose of the arrow operator (->) in C++?
a data type.
12. Creation/Synthesis: Which of the following correctly defines a function that accepts a structure
pointer as a parameter in C++?
13. Application: How can you dynamically allocate memory for an array in C++?
15. Creation/Synthesis: Which of the following correctly declares a dynamic array in C++ using pointers?
c) int arr[3];
d) int *arr;
16. Application: How can you access an element in an array using a pointer in C++?
18. Creation/Synthesis: Which of the following correctly declares a structure variable in C++?
20. Evaluation: What is the purpose of the "const" keyword in function parameters in C++?
Answer: b) It specifies that the function cannot modify the parameter value.
21. Creation/Synthesis: Which of the following is the correct way to declare a function that accepts an
array as a parameter in C++?
) {}
22. Application: How can you return a structure from a function in C++?
Answer: b) It specifies that a variable retains its value across function calls.
24. Creation/Synthesis: Which of the following is the correct way to declare a static variable inside a
function in C++?
d) int var;
25. Application: How can you pass a structure by value to a function in C++?
26. Evaluation: What is the purpose of the "return" statement in a function in C++?
27. Creation/Synthesis: Which of the following correctly declares a pointer to a structure in C++?
a) struct *ptr;
b) struct ptr;
28. Application: How can you access the value stored at a memory address using a pointer in C++?
30. Creation/Synthesis: Which of the following is the correct way to delete a dynamically allocated array
in C++?
a) delete arr;
b) delete[] arr;
c) free(arr);
d) clear(arr);
Certainly! Here are 30 multiple-choice questions related to I/O functionality for reading from and writing
to data and text files. Each question is followed by its answer:
1. Creation/Synthesis: Which header file is required to work with file I/O in C++?
a) \<iostream\>
b) \<fstream\>
c) \<cstdio\>
d) \<string\>
Answer: b) \<fstream\>
2. Application: Which mode should be used when opening a file to write data and discard the file's
current content?
a) std::ios::app
b) std::ios::trunc
c) std::ios::in
d) std::ios::out
Answer: b) std::ios::trunc
4. Creation/Synthesis: Which of the following is the correct way to open a file named "data.txt" for
reading in C++?
5. Application: How can you check if a file has been successfully opened in C++?
6. Evaluation: Which function is used to read a single character from a file in C++?
a) getline()
b) get()
c) read()
d) put()
Answer: b) get()
7. Creation/Synthesis: Which of the following is the correct way to read a line of text from a file in C++?
a) getline(file, str);
c) read(file, str);
d) file.getline(str);
Answer: a) getline(file, str);
8. Application: How can you check if the end of a file has been reached in C++?
10. Creation/Synthesis: Which of the following is the correct way to open a file named "output.txt" for
writing in C++?
a) put()
b) read()
c) write()
d) get()
Answer: a) put()
a) getline()
b) put()
c) read()
d) write()
Answer: d) write()
13. Creation/Synthesis: Which of the following is the correct way to check if a file write operation was
successful in C++?
14. Application: How can you move the file pointer to a specific position within a file in C++?
a) seekp()
b) seekg()
c) seek()
d) movep()
Answer: b) seekg()
Answer: a) It returns the current position of the file pointer for reading.
16. Creation/Synthesis: Which of the following is the correct way to close a file in C++?
a) file.close();
b) close(file);
c) fclose(file);
d) file.end();
Answer: a) file.close();
17. Application: How can you check if a file exists before opening it in C++?
18. Evaluation: What is the purpose of the ios::app mode when opening a file in C++?
19. Creation/Synthesis: Which of the following is the correct way to read binary data from a file in C++?
b) file.read(buffer, size);
c) getline(file, buffer);
b) file.write(buffer, size);
c) put(file, buffer);
d) putline(file, buffer);
21. Evaluation: What is the purpose of the ios::binary mode when opening a file in C++?