Week 1 Flashcards

1
Q

Objects are instances of _______

A

classes

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

Object-oriented languages offer three high-level features for programming solutions:

A

encapsulation
inheritance
polymorphism

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

fundamental types:

A

correspond directly to the. hardware facilities

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

built-in types:

A

reflect the capabilities of the hardware facilities directly and efficiently

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

User-defined types

concrete types:
abstract types:

A

concrete types - their representation is part of their definition and is known

abstract types - their representation is not part of their definition and is unknown

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

declaration:

A

A declaration introduces a name into a program and associates that name with a type.

ex.
int x;

void display();

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

4 types of scopes:

A

local scope - the name has been declared within a function or code block

class scope - the name has been declared as a member of a class

namespace scope - the name has been declared as a member of a named block

global scope - the name has not been declared in any one of the above scopes

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

linkage:

A

A name has a linkage if it can refer to an identical name declared in another scope. Linkage is optional.

The linkage of a name may be

external - connected across different scopes in different modules

internal - connected across different scopes within the same module

non-existent - not connected to any entity outside its own scope

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

memory distinctions:

A

code segment - stores the program instructions

data segments - store data that survives the lifetime of the program

stack segment - stores local data that is, statically allocated

heap segment - stores local data that is dynamically allocated

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

definition:

A

A definition is a declaration that associates a meaning with a name. A declaration may be a definition but is not necessarily a definition.

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

one-definition rule:

A

A definition may not appear more than once across all translation units. No translation unit may contain more than one definition of a variable, function, class or template. If a definition appears in multiple translation units, that definition must be identical in all translation units in which it appears.

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

scope:

A

The scope is the region of the program throughout which the name is valid; that is, the region where the entity identified by that name is visible.

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

initializer expressions:

A

The scope of a name declared in the selection condition of a selection construct extends to the end of the construct itself.

ex.
if (int j = i % 10; j < 5) {
i -= j;

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

access a shadowed global variable with the name ‘x’:

A

use the scope resolution operator:

::x

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

external linkage:

A

A name with external linkage refers to an entity that is declared in a different scope within another translation unit. The C++ keyword extern identifies external linkage.

ex.

extern int share_me; // declaration

We omit this linkage keyword in the translation unit that defines and initialize the named entity:

int share_me = 0; // definition

C++ ignores the extern keyword if an initialization is present.

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

internal linkage:

A

A name with internal linkage refers to an entity that is invisible outside its own translation unit, but visible to other scopes within its translation unit. The C++ keyword static identifies internal linkage.

ex.

static int local = 2;

17
Q

what is a volatile type?

A

A value stored in a volatile type is subject to side-effects and needs its memory location updated every single time that the CPU changes that value.

18
Q

what is a type definition?

A

A type definition is an alias for a type. A type definition can simplify code readability for compound types.

The C++ keyword typedef identifies a synonym for a specified type. A type definition takes the form

typedef compoundType Synonym;

19
Q

namespaces:

A

A namespace is a scope that limits the visibility of its names with respect to the program as a whole.

20
Q

using declaration:

A

To minimize repetition of scope resolution, we can expose a name within a namespace by a using declaration. A using declaration takes the form

using namespace::identifier;

21
Q

anonymous namespaces:

A

Anonymous namespaces provide a means of isolating names within a translation unit. The names declared within an anonymous namespace are only visible inside their own translation unit and invisible to all other translation units. If a definition appears in multiple translation units, it can differ across the translation units if it is within anonymous namespaces in each translation unit.

ex.
namespace {
// code here
}
22
Q

good design practice - using declarations:

A

using declarations and directives complicate header file inclusions.

Since we cannot determine the order in which header files will be included within another source file, we qualify all names within the header file with their namespace’s identifiers and the scope resolution operator. It is good design practice to avoid the using directive or declaration in any header file.

23
Q

The storage duration of a variable or object defines its lifetime within a program. Storage duration may be one of the following:

A

automatic - lasts from its declaration to the end of its scope - no keyword

static - lasts the entire lifetime of the program - use keyword static

dynamic - created using the keyword new - last until deallocated using the keyword delete

thread - lasts the lifetime of the thread - use keyword thread_local

24
Q

Three stages of the compilation process:

A

Pre-Processing Stage - the pre-processor creates a separate translation unit from the original source files for each module by inserting the header files into the implementation file and replacing or expanding any macros (lines starting with #)

Compilation Stage - the compiler creates a separate binary file from each translation unit

Linking Stage - the linker creates a single relocatable file from the binary files for all translation units and the binary files for any referenced libraries.

25
Q

Compiler options:

A

/c compile only without a link stage - create a .obj binary file.

/E pre-process only - send the output to stdout.

/P pre-process only - send the output to *.i file.

/Wall enable all warnings.

26
Q

Linux GCC compiler options:

A
  • c pre-process and compile without a link stage - create a .o binary file.
  • E pre-process only - send the output to stdout.
  • g produce information for the debugger (gdb).
27
Q

What are the optional command-line arguments the function ‘int main()’

A

int main(int argc, char *argv[]);

The first parameter (argc) in the command-line-arguments version of the main() function receives the number of arguments supplied on the command line from the operating system. This number includes the name of the relocatable file. The second parameter (argv) receives the address of an array of pointers to C-style null-terminated strings. Each pointer holds the address of a string that holds one command-line argument. argv[0] holds the address of the name of the relocatable file. argv[i] holds the address of the C-style null-terminated string that holds the i-th command-line argument.

28
Q

What is the keyword ‘constexpr’ used for?

A

The constexpr keyword declares that the value of its identifier is a run-time constant and can be evaluated at compile time.

ex.

constexpr int N = 8; // constant variable

constexpr int factorial(int i) { // constant function
return i > 1 ? i * factorial(i - 1) : 1;

29
Q

What is the keyword ‘static_assert’ used for?

A

The static_assert() mechanism generates a custom compiler error message if the specified condition is not met.

static_assert(bool condition, const char* message);

ex.
static_assert(N > 0, “N <= 0”);