Beruflich Dokumente
Kultur Dokumente
2) Difference between
float *p1[100] ; // p1 is an array of 100 pointers (each pointing to a float
variable)
float (*p2)[100] // p2 is a pointer to an array which contains 100 floats.
Due to Associativity.
5) Header Gaurds
#ifndef _ABC_H_
#define _ABC_H_
...
...
endif
6) What is initialization list and when it is mandatory
class ABC {
public:
ABC(v1,v2,v3): mem_a(v1),mem_b(v2) {
mem_c=v3;
}
}
to initialze constant and reference member variables of a class, initiallization
lists are mandatory. They offer better performnace by eliminating temporary
vars.
7) Abstract Class. Class with pure virtual functions is called abstract class.
Can not be instantiated.
class ABC {
virtual method_1() = 0; //pure viirtual function
virtual method_2();
}
During runtime, depending upon the type of the object pointed to by the base
pointer, the corresponding method will be called.
class Base {
public:
virtual int f1();
}
class Der_1: public Base {
public:
int f1();
}
If in the Base decleration, the ''virtual" keyward is not present before the f1()
decleration, bp->f1() willl always call Base f1() iirrrespective of to which
object this bp is now pointing to, as the decision of func call willl be taken
during compile time rather than at rruntime due to this compiler cannot
decide to which objct bp is pointing to .
9) long a=5;
int b=sizeof(a++)
what is the value of a?
'a' value willl be stilll be 5, as 'sizeof' is an operrator and its arguments are
evaluated for type and the actual evaluation does not happen. type of 'a++'
expression is an int, so b will be assigned either 4 (for 32bit builds) or 8 (for
64bit builds)
return p_instance;
}
}
How about deletion of this single instance?
11) alloca ?
Usually dynamic memory allocated by mallloc, calloc, realloc, new are
allocated in the Heap.
but 'alloca' function is used to allocate dynamiic memory in the stack instead
of in the Heap. This alllocated memory will be freed automaticallly when the
currently active function returns
p3 is a constant pointer. It can act as both read and write handle. It can read
and change the value it is pointing to. But once after this pointer is initialized
to point to an object, this cannot be changed to point to a different object
during its entire life time. From its inception to its end, it willl be pointing to
the same object as it is initialized with.
*p3 = 84; is allowed. It will change the value of 'c' to 84. But
p3= &another_int
is not allowed.
p3++ is also not alllowed as this iis trying too point to a new address.
however (*p3)++ is alowed, this willl increment the value of 'c'
Complex c1(3,7)
int x=c1 ; // 'operator int' conversion function is called and 3+7 is returned
to 'x' .
char *ptr=c1 // 'operator char*' is called and '3+i7' string is returned to ptr
withoout the above conversion operators, these assignments are illegal and
willl resullt n comppillation failures