0
0
C++programming~5 mins

Class definition syntax in C++ - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the basic syntax to define a class in C++?
A class in C++ is defined using the <code>class</code> keyword followed by the class name and a pair of curly braces containing members. Example:<br><pre>class MyClass {<br>  // members<br>};</pre>
Click to reveal answer
beginner
What are the two main sections inside a C++ class for member access?
The two main access specifiers are public: and private:. public members can be accessed from outside the class, while private members can only be accessed from within the class.
Click to reveal answer
beginner
How do you declare a member function inside a class?
Inside the class, you declare a member function by specifying its return type, name, and parameters. Example:<br><pre>class MyClass {<br>public:<br>  void greet();<br>};</pre>
Click to reveal answer
beginner
What is the purpose of the semicolon after the closing brace in a class definition?
In C++, the class definition must end with a semicolon <code>;</code>. This tells the compiler that the class definition is complete.
Click to reveal answer
beginner
Can you define member variables inside a class? How?
Yes, member variables are defined inside the class body, usually under <code>private:</code> or <code>public:</code>. Example:<br><pre>class MyClass {<br>private:<br>  int age;<br>public:<br>  int id;<br>};</pre>
Click to reveal answer
Which keyword is used to define a class in C++?
Astruct
Bclass
Cobject
Ddefine
What symbol must appear after the closing brace of a class definition?
A.
B:
C;
D,
Which access specifier allows members to be accessed from outside the class?
Ainternal
Bprotected
Cprivate
Dpublic
How do you declare a member function inside a class?
ABy writing its return type, name, and parameters inside the class
BBy defining it outside the class only
CBy using the keyword <code>function</code>
DBy declaring it as a variable
Where are member variables usually declared inside a class?
AInside <code>public:</code> or <code>private:</code>
BOnly inside <code>private:</code>
COnly inside <code>public:</code>
DOutside the class
Explain the basic syntax of defining a class in C++ and the role of access specifiers.
Think about how you group related data and functions together and control who can see them.
You got /5 concepts.
    Describe how to declare member variables and member functions inside a C++ class.
    Remember, variables hold data and functions do actions inside the class.
    You got /4 concepts.