0
0
C++programming~5 mins

Data members and member functions in C++ - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What are data members in a C++ class?
Data members are variables that hold the data or state of an object created from a class. They represent the properties of the object.
Click to reveal answer
beginner
What are member functions in a C++ class?
Member functions are functions defined inside a class that operate on the data members. They define the behavior or actions of the object.
Click to reveal answer
intermediate
How do you access data members inside member functions?
Inside member functions, you can directly use data members by their names or use the this pointer to refer to the current object's data members.
Click to reveal answer
intermediate
Can member functions modify data members? Explain.
Yes, member functions can modify data members unless the function is declared as <code>const</code>. Non-const member functions can change the object's state.
Click to reveal answer
beginner
What is the difference between public and private data members?
<code>Public</code> data members can be accessed from outside the class, while <code>private</code> data members can only be accessed within the class or by friend functions/classes.
Click to reveal answer
Which of the following is a data member in a class?
Aint age;
Bvoid display();
Cclass Person {}
Dreturn 0;
What keyword is used to define a member function outside the class?
Aclass
Bnamespace
C:: (scope resolution operator)
Dtemplate
Which access specifier restricts access to data members only within the class?
Apublic
Bprivate
Cprotected
Dexternal
Can a const member function modify data members?
AOnly if data members are mutable
BNo, never
COnly if data members are public
DYes, always
How do member functions help in object-oriented programming?
AThey store data
BThey create new classes
CThey delete objects
DThey define object behavior
Explain what data members and member functions are in a class and how they relate to an object.
Think about how a real-world object has properties and actions.
You got /3 concepts.
    Describe the difference between public and private data members and why access control is important.
    Consider why some information should be hidden from outside access.
    You got /3 concepts.