Lab 1 : C++ revision Flashcards

1
Q

A class may have …….. constructors& ………..destructors.

A

A class may have MANY constructors but ONLY ONE destructor.

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

Constructor is automatically called at ……………………. while destructor is automatically called at ………………

A
  • the creation (allocation) of a new object.
  • the termination (de-allocation).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what’s a class constructor?

A

A class constructor is a special member function of a class that is executed whenever we create new objects of that class.

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

what is the return type of a constructor ?

A

A constructor will have exact same name as the class and it does NOT have any return type at all, not even void.

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

why do we use constructors ?

A

SETTERS :- Constructors can be very useful for setting initial values for member variables

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

example of a setter and a getter

A

void SetLength( double len );
double GetLength( void );

set bakhod input bs msh btala3 output .
get , the output , doesnt need input.

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

what is a “statically - typed” programming language ?

A

A programming language is said to use static typing when type checking is performed during compile-time as opposed to run-time.

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

what is an ANSI standard?

A

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

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

sizeof() operator is used for ………….

A

to get size of various data types in bytes.
example:- sizeof(double)

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

numeric_limits <int> :: min()
numeric_limits <int> :: max()</int></int>

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

how can you create a new name for a data type ?

A

You can create a new name for an existing type using typedef
example:-
typedef type newname;
typedef int integer;

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

enum enum-name { list of names } var-list;
enum color { red, green, blue } c;
c = blue;

A

the following code defines an enumeration of colors called colors and the variable c of type color.
c is assigned the value “blue”.

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

enum color { red, green = 5, blue };

A

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.

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

A variable definition tells the compiler where and how much storage to create for the variable

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

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

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

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.

A
17
Q

here are three places, where variables can be declared :-

A

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.”

18
Q

A program can have same name for local and global variables but value of local variable inside a function will take preference.

A
19
Q

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

A
20
Q

Constants refer to fixed values that the program may not alter and they are called ………

A

literals.

21
Q

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;
A
22
Q

The data type modifiers are: −

signed
unsigned
long
short

A
23
Q

the following two statements both declare unsigned integer variables.

unsigned x;
unsigned int y;

A
24
Q

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.

A
25
Q

A storage class defines:-
1) the scope (visibility)
2) life-time of variables and function

A

storage classes :-
auto
register
static
extern
mutable

26
Q

auto storage class is the default storage class for all local variables. i.e:- can only be used within functions

A
27
Q

the register storage class is used to define local variables that should be stored in a register instead of RAM.
This means that the variable has a maximum size equal to the register size (usually one word) and can’t have the unary ‘&’ operator applied to it (as it does not have a memory location).

A
28
Q

The static storage class instructs the compiler to keep a local variable in existence during the life-time of the program instead of creating and destroying it each time it comes into and goes out of scope

A
29
Q

The static modifier may also be applied to global variables. When this is done, it causes that variable’s scope to be restricted to the file in which it is declared

when static is used on a class data member, it causes only one copy of that member to be shared by all objects of its class.

A
30
Q

The extern storage class is used to give a reference of a global variable that is visible to ALL the program files.

When you use ‘extern’ the variable cannot be initialized as all it does is point the variable name at a storage location that has been previously defined.

When you have multiple files and you define a global variable or function, which will be used in other files also, then extern will be used in another file to give reference of defined variable or function

extern is used to declare a global variable or function in another file.

A
31
Q

The mutable specifier applies only to class objects

It allows a member of an object to override const member function. That is, a mutable member can be modified by a const member function.

A
32
Q

control statements:-
1 break/switch statement
Terminates the loop and transfers execution to the statement immediately following the loop or switch.

2 continue statement
Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.

A
33
Q

Exp1 ? Exp2 : Exp3;

Exp1 is evaluated. If it is true, then Exp2 is evaluated and becomes the value of the entire ‘?’ expression. If Exp1 is false, then Exp3 is evaluated and its value becomes the value of the expression.

A
34
Q

A function declaration tells the compiler about a function’s name, return type, and parameters. A function definition provides the actual body of the function.

A
35
Q
A