Lab 1 : C++ revision Flashcards
A class may have …….. constructors& ………..destructors.
A class may have MANY constructors but ONLY ONE destructor.
Constructor is automatically called at ……………………. while destructor is automatically called at ………………
- the creation (allocation) of a new object.
- the termination (de-allocation).
what’s a class constructor?
A class constructor is a special member function of a class that is executed whenever we create new objects of that class.
what is the return type of a constructor ?
A constructor will have exact same name as the class and it does NOT have any return type at all, not even void.
why do we use constructors ?
SETTERS :- Constructors can be very useful for setting initial values for member variables
example of a setter and a getter
void SetLength( double len );
double GetLength( void );
set bakhod input bs msh btala3 output .
get , the output , doesnt need input.
what is a “statically - typed” programming language ?
A programming language is said to use static typing when type checking is performed during compile-time as opposed to run-time.
what is an ANSI standard?
The ANSI standard is an attempt to ensure that C++ is portable; that code you write for Microsoft’s compiler will compile without errors, using a compiler on a Mac, UNIX, a Windows box, or an Alpha
sizeof() operator is used for ………….
to get size of various data types in bytes.
example:- sizeof(double)
numeric_limits <int> :: min()
numeric_limits <int> :: max()</int></int>
how can you create a new name for a data type ?
You can create a new name for an existing type using typedef
example:-
typedef type newname;
typedef int integer;
enum enum-name { list of names } var-list;
enum color { red, green, blue } c;
c = blue;
the following code defines an enumeration of colors called colors and the variable c of type color.
c is assigned the value “blue”.
enum color { red, green = 5, blue };
the value of the first name is 0, blue will have a value of 6 because each name will be one greater than the one that precedes it.
A variable definition tells the compiler where and how much storage to create for the variable
A variable declaration has its meaning at the time of compilation only,
Though you can declare a variable multiple times in your C++ program, but it can be defined only once in a file, a function or a block of code