Estudo de C++ Flashcards

Aprender C++

1
Q

Dereference operator

A

Give access to real valor on the variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Reference operator

A

Give access to memory address

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Keyword New

A

Creates and initializes objects with dynamic storage

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Keyword Delete

A

Erase variables after use

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Struct

A

structure for grouping variables, from different types

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Classes

A

Extension of struct concept, can have functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Data in structs

A

Atributes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Functions in Classes

A

Also called methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Object

A

Takes attributes and methods from classes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Object

A

We use it to access what is in classes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Default classes

A

Everything after a declared class and before a specifier is PRIVATE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Scope operator

A

::

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Scope operator definition

A

To show that a function is a implementation from a member from a class, not a global function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Constructor

A

Special method called when a new object is created

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Using Constructor

A

Need to have the same name as the classes and no return valor, even VOID

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Destructor

A

Called when an object is destroyed(when a function ends or when we use DELETE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Using Destructor

A

Need the same name as the class and a precede “~”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Destructor advantages

A

Good for memory releasing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Common practices in C++ with classes

A

Creating two separated files

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

pragma once

A

Preprocessor directive to include the header once, regardless how many times he has been imported

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Declaring a classes as STATIC

A

We don’t need to instantiate a classes for using it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Static class example

A

“static int math::pow();”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Non static class example

A
"Math math = new Math();"
"math.pow();"
24
Q

Function in static class

A

Need to be static too

25
Q

Constructor types

A

Most time are publics, but i can have private constructor too

26
Q

How many constructs can I have?

A

Classes can have multiples constructors

27
Q

What happens if I don’t create a constructor?

A

My compiler creates a constructor automatically

28
Q

How many default constructors a class have?

A

One, and just one

29
Q

Default constructor example

A
class Person
{
    public:
        Person();
        ~Person();
};
30
Q

From what should I make sure to initialize my own constructor?

A

Because pointers and arrays can initialize with undefined values.

31
Q

The complex reason for my own constructor?

A

When I have a class inside a class, my compiler is unable to initialize that member

32
Q

Summarizing the ‘this’ operator - pt 1

A

This serves for refer to attributes and methods from a class

33
Q

Summarizing the ‘this’ operator - pt 2

A

When you create an object(instantiate a class), you pass the values in the constructor and we can have methods overloading.

34
Q

Summarizing the ‘this’ operator - pt 3(when use it)

A

Use the ‘this’ operator when I need to access anything inside a class

35
Q

Keyword ‘new’

A

It’s used for allocate memory for an object in execution time

36
Q

Keyword ‘delete’

A

Releases memory after using an object and it’s no more needed

37
Q

Class Scope

A

In classes context, refer to member variables and member functions within the class definition

38
Q

Inside a class

A

Every variable and function is available for the functions inside the class

39
Q

Members modifiers

A

Every member from a class can have access to modifiers like ‘private’, ‘public’ and ‘protected’

40
Q

Private and public members availability

A

All the members are available for all members functions inside the class

41
Q

Accessing members inside a class

A

When accessing I need to use the dot operator(‘.’) or arrow(‘->’)

42
Q

Difference between dot and arrow

A

They have no difference, since they perform the same, but arrows it’s normally used with pointers and dot with variables

43
Q

Why use the arrow ->?

A

To replaces the following syntax:

(*a).b

44
Q

Accessing statics classes

A

I need to use the class name like “Math::Sum() instead instantiating like “Math myMath” and after this “myMath.Sum()”

45
Q

The compiler and class scope concept

A

The compiler knows what function he needs to call, because the object used it’s associated with an specific class. He knows the difference between ‘person.SayHello()’ and ‘dog.SayHello()’

46
Q

Encapsulation concept in OOP

A

We can say that it allows to include data and functionalities in a single package.

47
Q

The second definition of encapsulation

A

It’s to hide or restrict data. For example we don’t want to a Person class User defines the variables “firstName”, ‘lastName’ and age directly, only using the constructor

48
Q

A good practice within encapsulation scope

A

A good practice is to provide public functions to allow classes users to modify values, but indirectly

49
Q

Using a public function to modify allow me to do…

A

M, as a programmer, control how the users data are processed

50
Q

An example of treated data…

A

I can use a function to check if a user passed a negative value or a character instead a valid value for an age variable

51
Q

Resuming encapsulation

A

When using it, we define how attributes and methods are accessed

52
Q

Limiters…

A

private, public and protected

53
Q

The important part of encapsulation?

A

That the user don’t see how we define values or validates data

54
Q

The encapsulation analogy

A

We don’t need to know how a motor inside a car works, I need only to know how to drive him

55
Q

Namespaces

A

He acts like a container, we put variables, classes or another identifiers to avoid name conflicts

56
Q

Namespaces example: cout

A

He exists only in the std scope, that’s why we use:
std::cout or
using namespace std;
cout &laquo_space;‘Hello world’ &laquo_space;endl;