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
Expressions that refer to a memory location is called “lvalue” expression
The term rvalue refers to a data value that is stored at some address in memory. appears on the right side ONLY in an assignment expression.
here are three places, where variables can be declared :-
Inside a function or a block which is called “local variables,”
In the definition of function parameters which is called “formal parameters.”
Outside of all functions which is called “global variables.”
A program can have same name for local and global variables but value of local variable inside a function will take preference.
When a local variable is defined, it is not initialized by the system, you must initialize it yourself. Global variables are initialized automatically by the system when you define them
Constants refer to fixed values that the program may not alter and they are called ………
literals.
There are two simple ways in C++ to define constants −
- Using #define preprocessor.
#define identifier value
#define WIDTH 5 - Using const keyword.
const type variable = value;
const int WIDTH = 5;
The data type modifiers are: −
signed
unsigned
long
short
the following two statements both declare unsigned integer variables.
unsigned x;
unsigned int y;
data type qualifiers :-
1) const
Objects of type const cannot be changed by your program during execution.
2)volatile
The modifier volatile tells the compiler that a variable’s value may be changed in ways not explicitly specified by the program.
3)restrict
A pointer qualified by restrict is initially the only means by which the object it points to can be accessed.