W1: BLOCKS Flashcards

_ C++ Building Blocks

1
Q

W1-Q1: Which type of files the source code of a typical C++ module consists of? What are they used for?

A

_ a header file and an implementation file
_ Header file declares the name of its entities that are accessible by other modules.
These entities include values, variables, objects, references, functions, types, class members, templates, namespaces
_ Implementation file attaches meanings to those names

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

W1-Q2: What is a DEFINITION? Example

A
_ A definition is a declaration that associates a meaning with a name. 
_ A declaration IS a definition.
EX: include variable and object declarations, function definitions, parameter declarations in function definitions, class definitions, and template definitions.
_ A declaration IS not a definition.
EX: include function prototypes, parameter declarations in function prototypes, and forward class declarations.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

W1-Q3: Describe a DEFINITION RULE

A
_ A definition may not appear more than once in a translation unit. 
=> NO translation unit may contain more than one definition of a variable, function, class or template.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

W1-Q4: What is a SCOPE? List some types of scope

A

_ The scope is the REGION of the program throughout which the name is VALID (region where the entity associated with that NAME is VISIBLE)
_ The region starts at the name’s declaration and ends at the terminator for the region that hosts the declaration.
_ Block Scope, Class Scope, Global Scope

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

W1-Q5: What is BLOCK SCOPE?

A

_ A BLOCK is a set of program instructions enclosed within curly braces
_ A NAME declared within a block is local to that block.
_ extends from its declaration to the END of its block.

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

W1-Q6: What is CLASS SCOPE?

A
_ CLASS scope is the scope of a name declared in a class definition. 
_ extends from an object's construction to its destruction.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

W1-Q7: What is GLOBAL SCOPE?

A
_ GLOBAL scope refers to the ENTIRE region of a program. 
_ Names with global scope include class and function identifiers NOT defined in any other scope. 
_ A namespace localizes names of otherwise global scope.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

W1-Q8: What is SHADOWING?

A
_ A name declared within the scope of an IDENTICAL name shadows the entity that has the BROADER scope
_ The name of a variable declared within a member function shadows the instance variable with an identical name. 
_ Accessing the shadowed instance variable: this->name (this keyword)
_ The name of a variable within a class or a function shadows the entity with an identical name and global scope.
_ Accessing the shadowed global variable: (::name) (scope resolution operator)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

W1-Q9: Which keyword is used to identify EXTERNAL LINKAGE? What is EXTERNAL LINKAGE? Example.

A

_ The keyword extern identifies EXTERNAL linkage.
_ A name with EXTERNAL linkage refers to an entity that is declared in a scope within ANOTHER translation unit.
EX: extern int share_me; // declaration
_ omit linkage keyword and initialize the entity in the translation unit that defines the entity:
EX: int share_me = 0; // definition
_ ignores the extern keyword if an initialization is PRESENT.

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

W1-Q10: Which keyword is used to identify INTERNAL LINKAGE? What is INTERNAL LINKAGE? Example.

A

_ The keyword static identifies INTERNAL linkage.
_ 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.
EX: static int local = 2;

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

W1-Q11: What is a TYPE? List some characteristics of type?

A

_ A type describes how to interpret the BIT string in MEMORY associated with the name.
_ The type may be fundamental, built-in or a user-defined.

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

W1-Q12: HOW TO identify specific storage properties that are exhibited by a TYPE? List some types of cv-qualifiers.

A

_ using cv-qualifiers.
_ none - the type is MODIFIABLE and NOT subject to any side-effects
_ const - the type is UNMODIFIABLE and NOT subject to any side-effects
_ volatile - the type is MODIFIABLE and subject to some side-effects
_ const volatile - the type is UNMODIFIABLE and subject to some side-effects

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

W1-Q13: What does a const type hold? When including the keyword in the declaration, what does this inform the compiler?

A

_ holds an IMMUTABLE value

_ The compiler should REJECT any code that attempts to MODIFY the value of the declared object.

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

W1-Q14: What does a volatile type hold?

A

_ holds a value that is subject to some side-effects + needs its memory location updated every single time that the CPU changes its value.

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

W1-Q15: A type without a qualifier is?

A

cv-unqualified

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