QUIZ 1 Flashcards
Namespace
Region that provides scope for identifiers declared inside .
Syntax:
namespace name{
Body
}
Nested Namespace declaration
Namespace f{
Namespace p{
Namespace d{
//……
}
}
}
Or Namespace f :: s :: d;
InLine Namespaces
Dynamic Memory Allocation
Delete:
For arrays- delete [ ]
For non-arrays - delete
Member Selection Operator
‘ . ‘
Data Encapsulation
Interface and Implementation
int getCount () const {
//….
}
Const cannot change the value of an object. I.e it cannot change data attributes
Passed by reference vs Passed by Value
Passed by Reference: No copy of the original variable is made. Any change in referenced variable will affect original variable
Passed by value: A copy of original variable is made. Any change in parametered variable will not affect original variable.
Copy vs modify
Copy- propagatea source object value without modifying it
Move- propagates source object value and also is permitted to modify it
Constructor
Member function that is called automatically when object is created to initialize its values
-Cannot be called directly
-Has no return type
-Can be overloaded
Default constructors
-Have no parameters and can be called without arguments (cuz it doesn’t have parameters)
In Constructors declaration order matters
If a constructor has data attributes {
int t;
int v;
void R {};
in int main(){
Constructor object ( );
t, v and then R will be called bc no specification
Constructor Overloading
Same constructor names, different data attributes
Defaulted Default constructor
Constructor not explicitly declared? The compiler will assume a defaulted default constructor. It won’t be there but it will be called. Almost like a ghost constructor.
Literals
Boolean - true, false
Pointer -nullptr
Declaration vs Definition
Declaration- introduces indentifier
Definition- introduces identifier and also discloses full information about it e.g memory allocation
Declaration vs Definition
Declaration- introduces indentifier
Definition- introduces identifier and also discloses full information about it e.g memory allocation
Enumerators
User-defined data type
E.g., enum