Introduction to CPP

8 important questions on Introduction to CPP

Where are functions and classes usually declared?

In the header file (.h).

Where are functions and classes defined?

In ".cpp" files.


Headers let the compiler, and you!, know the (1) of the functions you will use, which can be (2) in other “.cpp” files, or in libraries.

Fill in the words at (1) & (2)

  1. type (declaration)
  2. defined
  • Higher grades + faster learning
  • Never study anything twice
  • 100% sure, 100% understanding
Discover Study Smart

Should file names match? (.h & .cpp)

No, as they can be included at will.

How many times may a header file be included? And how to avoid more?

Only once, to avoid more use: #ifndef ->if not defined and then #define

How are namespaces declared and used?

Surround the function definitions with: namespace NiceName { void functionA() }

The namespace can then be used as follows: NiceName::functionA()

What should be placed after the closing bracket of a class definition?

A semicolon.

How to do a call-by-reference and a call-by-value?

The call-by-value is the standard mode, thus creating a new variable will also mean that the value is copied in a new place in the memory.

The call-by-reference can be done by adding a & after the variable type (e.g. int&), meaning that the new value of the variable is referenced, to another variable's place in memory. Changing reference variable A also changes referenced variable B.

The question on the page originate from the summary of the following study material:

  • A unique study and practice tool
  • Never study anything twice again
  • Get the grades you hope for
  • 100% sure, 100% understanding
Remember faster, study better. Scientifically proven.
Trustpilot Logo