W1: BLOCKS Flashcards
_ C++ Building Blocks
W1-Q1: Which type of files the source code of a typical C++ module consists of? What are they used for?
_ 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
W1-Q2: What is a DEFINITION? Example
_ 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.
W1-Q3: Describe a DEFINITION RULE
_ 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.
W1-Q4: What is a SCOPE? List some types of scope
_ 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
W1-Q5: What is BLOCK SCOPE?
_ 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.
W1-Q6: What is CLASS SCOPE?
_ CLASS scope is the scope of a name declared in a class definition. _ extends from an object's construction to its destruction.
W1-Q7: What is GLOBAL SCOPE?
_ 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.
W1-Q8: What is SHADOWING?
_ 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)
W1-Q9: Which keyword is used to identify EXTERNAL LINKAGE? What is EXTERNAL LINKAGE? Example.
_ 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.
W1-Q10: Which keyword is used to identify INTERNAL LINKAGE? What is INTERNAL LINKAGE? Example.
_ 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;
W1-Q11: What is a TYPE? List some characteristics of type?
_ 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.
W1-Q12: HOW TO identify specific storage properties that are exhibited by a TYPE? List some types of cv-qualifiers.
_ 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
W1-Q13: What does a const type hold? When including the keyword in the declaration, what does this inform the compiler?
_ holds an IMMUTABLE value
_ The compiler should REJECT any code that attempts to MODIFY the value of the declared object.
W1-Q14: What does a volatile type hold?
_ holds a value that is subject to some side-effects + needs its memory location updated every single time that the CPU changes its value.
W1-Q15: A type without a qualifier is?
cv-unqualified