Q1) int a[10[15];
char b[10[15];
What will be the location of a[3][4], if base location a[0][0] is ox1000?
What will be the location b[3][4], if base location b[0][0] is ox2000?
(a) ox10C4 (b) ox2031
Let me know if you need the solution in detail.
Q2) How can the unary operator ++ be overloaded in C++ for postfix operation ?Let me know if you need the solution in detail.
See Answer
We need to declare postfix notation with an int inside: A operator++(int); // postfix
Prefix declaration is declared without int in the brackets: A operator++(); // prefix
Example definition of a postfix operator
Prefix declaration is declared without int in the brackets: A operator++(); // prefix
Example definition of a postfix operator
//Example definition of a postfix operator A A::operator++(int) { // Create a temporary variable with our current digit A temp= A(); // Use prefix operator to increment this digit ++(*this);// apply operator // return temporary result return temp; // return saved state }
Q3)
fun(int a)
{
static int b;
}
what is the storage allocation for both a and b ?
See Answer
a will be stored in stack while b will be stored in the data segment (as it is a static variable, shared across the function calls)
Q4) How can we initialize a const data member in a class?
See Answer
Class sample{ Const int i; Public: sample(int j):i(j){ } };
Q5) Class D: public B2, B1; what is the order of execution of constructors and destructors of classes D, B1 and B2.
See Answer
Constructors: B2 -> B1 -> D
Destructors: D -> B1 -> B2
Destructors: D -> B1 -> B2
Q6) Allocate a 2-D array using new such that its elements to be accessed as a[i][j].
See Answer
Int (*p)[MAXCOL]
P = new int[MAXROW][MAXCOL]
Facebook Comments