Introduction to Programming MCQs with Answers
Practice important Introduction to Programming MCQs with answers and explanations.
Multiple Choice Questions
Q481: How does a C++ structure differ from a class in terms of member access control?
- A: Structure members are private by default
- B: Class members are public by default
- C: Structure members are public by default
- D: Structure and class members are both private by default
View Answer
C
Q482: What is the purpose of sizeof operator in memory allocation?
- A: To determine the size of a type
- B: To allocate memory
- C: To deallocate memory
- D: To initialize memory
View Answer
A
Q483: How does the delete operator work when used with an array?
- A: delete[] should be used
- B: delete should be used
- C: free should be used
- D: new should be used
View Answer
A
Q484: What is the purpose of friend functions in C++?
- A: To allow external functions to access private members
- B: To restrict access to public members
- C: To define member functions
- D: To declare new classes
View Answer
A
Q485: Where can you declare a friend function within a class?
- A: Only in the private section
- B: Only in the public section
- C: In either private or public section
- D: Only at the end of the class
View Answer
C
Q486: How do you declare a friend function in C++?
- A: friend function_name(return_type, parameters);
- B: friend return_type function_name(parameters);
- C: function_name(friend return_type, parameters);
- D: return_type friend function_name(parameters);
View Answer
B
Q487: Can a function from outside a class declare itself as a friend of that class?
- A: Yes, if the function has the right access level
- B: No, only the class can declare its friends
- C: Yes, if the class has no private members
- D: No, functions cannot declare themselves
View Answer
B
Q488: What does the friend keyword do in C++?
- A: It makes a function or class a member of another class
- B: It allows access to private members of a class
- C: It creates a new access level for functions
- D: It makes a class a subclass of another
View Answer
B
Q489: In which section of a class should a friend function typically be declared?
- A: It should be declared in the private section
- B: It should be declared in the public section
- C: It can be declared in either section
- D: It should be declared in the protected section
View Answer
C
Q490: How is a friend function defined outside a class?
- A: It includes the friend keyword in its definition
- B: It does not include the friend keyword in its definition
- C: It must be declared as static
- D: It must be a member function
View Answer
B