Skip to main content

Introduction to Programming MCQs with Answers

Practice important Introduction to Programming MCQs with answers and explanations.

Chapter: 28
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
Correct Answer: C
Chapter: 28
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
Correct Answer: A
Chapter: 28
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
Correct Answer: A
Chapter: 29
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
Correct Answer: A
Chapter: 29
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
Correct Answer: C
Chapter: 29
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);
Correct Answer: B
Chapter: 29
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
Correct Answer: B
Chapter: 29
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
Correct Answer: B
Chapter: 29
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
Correct Answer: C
Chapter: 29
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
Correct Answer: B
Chapter: 29
Q491:
If a class A declares a class B as its friend, what is the implication?
A. B can access all private members of A
B. A can access all private members of B
C. B and A have mutual access to each other
D. Neither class has special access to the other
Correct Answer: A
Chapter: 29
Q492:
Can a class declare multiple classes as friends?
A. No, only one friend class is allowed
B. Yes, multiple friend classes can be declared
C. Only if the classes are subclasses
D. No, friend declarations are limited to functions
Correct Answer: B
Chapter: 29
Q493:
What happens if you modify the private data member of a class using a friend function?
A. The private data member remains unchanged
B. The private data member is accessible to all functions
C. The private data member is modified by the friend function
D. The class’s private data is protected from changes
Correct Answer: C
Chapter: 29
Q494:
Which of the following is true about friend functions?
A. They can be members of the class they are friends with
B. They can access private and protected members
C. They must be declared in the public section
D. They cannot access private data members
Correct Answer: B
Chapter: 29
Q495:
What is the output if a friend function attempts to access a private member of a class?
A. It results in a compilation error
B. It has unrestricted access to private members
C. It causes a runtime error
D. It accesses public members only
Correct Answer: B
Chapter: 29
Q496:
When declaring a friend function that needs to access private members of multiple classes, what must be done?
A. Declare the friend function in one class only
B. Declare the friend function in each class involved
C. Declare the function as a member of one class
D. Use an interface class for declaration
Correct Answer: B
Chapter: 29
Q497:
What is the syntax to declare a class as a friend of another class in C++?
A. friend class ClassName;
B. class ClassName friend;
C. friend ClassName;
D. friend ClassName()
Correct Answer: A
Chapter: 29
Q498:
If two classes are friends of each other, what type of access do they have?
A. Mutual access to all private members
B. Limited access to each other’s public members
C. One-way access where each class can access the other’s private members
D. No special access; they interact as normal classes
Correct Answer: A
Chapter: 30
Q499:
What is a reference in C++?
A. An alias or synonym for a data type
B. A new variable
C. A pointer to a data type
D. An address of a variable
Correct Answer: A
Chapter: 30
Q500:
How do you declare a reference in C++?
A. int i &;
B. int &i;
C. &int i;
D. ref int i;
Correct Answer: B

Test Your Knowledge

Take a timed quiz on Introduction to Programming

🚀 Start Quiz Now