Custom C++ at Bremen | Flashcards & Summaries

Lernmaterialien für Custom C++ an der Bremen

Greife auf kostenlose Karteikarten, Zusammenfassungen, Übungsaufgaben und Altklausuren für deinen Custom C++ Kurs an der Bremen zu.

TESTE DEIN WISSEN
How does C++ works?
Lösung anzeigen
TESTE DEIN WISSEN
1. All source files get compiled (src == text we write). This includes the preprocessing step where the header files get copied into the source and the creation of the object files each for a src file.

2. The linker links / glues the object files together. afterwards an executable is created.
Lösung ausblenden
TESTE DEIN WISSEN

What is the library <iostream> good for?

Lösung anzeigen
TESTE DEIN WISSEN

For all possible outputs to the console:


std::cout etc.

Lösung ausblenden
TESTE DEIN WISSEN

Define a syntax that declares a static variable and a static function inside a class. Also give examples how to use both.

Lösung anzeigen
TESTE DEIN WISSEN

Declaration:

class X {

static int x;

static void Printx() {std::cout << x << std::endl};

};


Static variables must be declared before using them (they will not be declared once an object instance is created otherwise they would belong to that instance).

int X::x = 20;


Usage:

X max;

max.x = 10;

std::cout << max.x << X::x;

max.Printx();

X::Print();  


Consequently, the static is like using enums for classes / structs. Also it makes sense why it is that way because the variables / functions does not belong specifically to an object instance. 

Lösung ausblenden
TESTE DEIN WISSEN

Class oriented:

What is a destructor of a class? Give an example.

Lösung anzeigen
TESTE DEIN WISSEN

A destructor is the opposite of a constructor, so it is a special method that gets called once the object runs out of scope. It basically provides the opportunaty to clean up after the object instance gets deleted. Very usefull to unsign memory from stack or bring pointer etc. in a proper position.


class Example {

    ~Example () {

        some code

    }

};

Lösung ausblenden
TESTE DEIN WISSEN

When must the array size, of an static array, be known for declaration?

Lösung anzeigen
TESTE DEIN WISSEN

Before the compiler time.

Lösung ausblenden
TESTE DEIN WISSEN

How to declare an array of ints and char on the stack? 

Lösung anzeigen
TESTE DEIN WISSEN

Integers:

int arraY[] = {10, 20, ...};     // will read and fix the size

or

int array[3];                          // you define the size


Chars:

char arraY[] = "hello....";     // you can modify 

or

char arraY[20];                   // you can modify 

or 

const char* arraY = "name"; // you can't modify

Lösung ausblenden
TESTE DEIN WISSEN

Class basics:

What is a Virtual Function?

Lösung anzeigen
TESTE DEIN WISSEN

A function that keeps track which class it belongs to so that it can call the defined function from its proper object instance. This will be achieved via hash tables that keep track to what king of object the caller refers to.


Example:

class Entity {

public: std::string GetName() { return "Entity"; } };


class Memeber : public Entity {

    std::string m_name;

public:

    Memeber(const std::string& name) :m_name(name){}

    std::string GetName() { return m_name; } };


int main() {

    Memeber pers("Max");

    std::cout << pers.GetName() << std::endl; 

        

    Entity* member = &pers;

    std::cout << member->GetName() << std::endl;

    return 0; }


In this example the member belongs to the Entity class, however, it is initialized with a Member memory of pers. Polymorphism makes it possible to declare this. When calling member->GetName() we will get "Entity" that is actually incorrect, because we are clearly refering to the memory of a Member class. To solve this problem we need to set virtual infront of GetName() of the parents class. This will automatically solve our problem.

Lösung ausblenden
TESTE DEIN WISSEN

What is a translation unit?

Lösung anzeigen
TESTE DEIN WISSEN

A .cpp fie.

Lösung ausblenden
TESTE DEIN WISSEN
Give an example how #if false or #if true work.
Lösung anzeigen
TESTE DEIN WISSEN
Function is included:
#if true
some code
#endif

Function is excluded / hidden
#if false
some code
#endif
 
Lösung ausblenden
TESTE DEIN WISSEN

What are references?

Lösung anzeigen
TESTE DEIN WISSEN

Pointers with a easier syntax.



Lösung ausblenden
TESTE DEIN WISSEN

What is the syntax of declaring an array of 10 integers? Provide an example for defining it on the stack and the heap.

Lösung anzeigen
TESTE DEIN WISSEN

Creates the array on the stack which will be gone once it runs out of scope:

int example[10];


Creats the array on the heap which will live forever as long as we delete it or the program executes:

int* another = new int[10];


Lösung ausblenden
TESTE DEIN WISSEN

What kind of ways do you know to initialize a variable?

Lösung anzeigen
TESTE DEIN WISSEN

1. int a = 2;

2. int a(2);

3. int a{2}; // the prefered way



Lösung ausblenden
  • 34632 Karteikarten
  • 831 Studierende
  • 7 Lernmaterialien

Beispielhafte Karteikarten für deinen Custom C++ Kurs an der Bremen - von Kommilitonen auf StudySmarter erstellt!

Q:
How does C++ works?
A:
1. All source files get compiled (src == text we write). This includes the preprocessing step where the header files get copied into the source and the creation of the object files each for a src file.

2. The linker links / glues the object files together. afterwards an executable is created.
Q:

What is the library <iostream> good for?

A:

For all possible outputs to the console:


std::cout etc.

Q:

Define a syntax that declares a static variable and a static function inside a class. Also give examples how to use both.

A:

Declaration:

class X {

static int x;

static void Printx() {std::cout << x << std::endl};

};


Static variables must be declared before using them (they will not be declared once an object instance is created otherwise they would belong to that instance).

int X::x = 20;


Usage:

X max;

max.x = 10;

std::cout << max.x << X::x;

max.Printx();

X::Print();  


Consequently, the static is like using enums for classes / structs. Also it makes sense why it is that way because the variables / functions does not belong specifically to an object instance. 

Q:

Class oriented:

What is a destructor of a class? Give an example.

A:

A destructor is the opposite of a constructor, so it is a special method that gets called once the object runs out of scope. It basically provides the opportunaty to clean up after the object instance gets deleted. Very usefull to unsign memory from stack or bring pointer etc. in a proper position.


class Example {

    ~Example () {

        some code

    }

};

Q:

When must the array size, of an static array, be known for declaration?

A:

Before the compiler time.

Mehr Karteikarten anzeigen
Q:

How to declare an array of ints and char on the stack? 

A:

Integers:

int arraY[] = {10, 20, ...};     // will read and fix the size

or

int array[3];                          // you define the size


Chars:

char arraY[] = "hello....";     // you can modify 

or

char arraY[20];                   // you can modify 

or 

const char* arraY = "name"; // you can't modify

Q:

Class basics:

What is a Virtual Function?

A:

A function that keeps track which class it belongs to so that it can call the defined function from its proper object instance. This will be achieved via hash tables that keep track to what king of object the caller refers to.


Example:

class Entity {

public: std::string GetName() { return "Entity"; } };


class Memeber : public Entity {

    std::string m_name;

public:

    Memeber(const std::string& name) :m_name(name){}

    std::string GetName() { return m_name; } };


int main() {

    Memeber pers("Max");

    std::cout << pers.GetName() << std::endl; 

        

    Entity* member = &pers;

    std::cout << member->GetName() << std::endl;

    return 0; }


In this example the member belongs to the Entity class, however, it is initialized with a Member memory of pers. Polymorphism makes it possible to declare this. When calling member->GetName() we will get "Entity" that is actually incorrect, because we are clearly refering to the memory of a Member class. To solve this problem we need to set virtual infront of GetName() of the parents class. This will automatically solve our problem.

Q:

What is a translation unit?

A:

A .cpp fie.

Q:
Give an example how #if false or #if true work.
A:
Function is included:
#if true
some code
#endif

Function is excluded / hidden
#if false
some code
#endif
 
Q:

What are references?

A:

Pointers with a easier syntax.



Q:

What is the syntax of declaring an array of 10 integers? Provide an example for defining it on the stack and the heap.

A:

Creates the array on the stack which will be gone once it runs out of scope:

int example[10];


Creats the array on the heap which will live forever as long as we delete it or the program executes:

int* another = new int[10];


Q:

What kind of ways do you know to initialize a variable?

A:

1. int a = 2;

2. int a(2);

3. int a{2}; // the prefered way



Custom C++

Erstelle und finde Lernmaterialien auf StudySmarter.

Greife kostenlos auf tausende geteilte Karteikarten, Zusammenfassungen, Altklausuren und mehr zu.

Jetzt loslegen

Das sind die beliebtesten Custom C++ Kurse im gesamten StudySmarter Universum

Cestodes

University of Northern Philippines

Zum Kurs

Die all-in-one Lernapp für Studierende

Greife auf Millionen geteilter Lernmaterialien der StudySmarter Community zu
Kostenlos anmelden Custom C++
Erstelle Karteikarten und Zusammenfassungen mit den StudySmarter Tools
Kostenlos loslegen Custom C++