C++ Training 2014 : Mentor Graphics Noida

Is this your test? Login to manage it. If not, you can create a quiz just like it.

This is a non-interactive preview of the quiz content.

1.
1 point
What is the output of following program


#include &#60stdio.h&#62
int fred = 0;
void g(int fred) {
fred = 13 ;
}
int f() {
int fred = 42 ;
g( fred ) ;
return fred ;
}

int main()
{
printf("%d\n", f());

return 0;
}
2.
1 point
Endianness of machines (and impact on bit ordering and byte ordering) Assuming 32 bit machine, consider the following code sample:

int x = 0x01234567;

Following are statements about above code

A) On Big Endian machine, the 4th byte is 0x67
B) On Little Endian Machines, the 4th byte is 0x01
C) The ordering of bits within a byte is independent of endianness.

Which of the statements are true?
3.
1 point
What is the size of the following class (for 32 bit machines)

class A{
int a;
public:
virtual int getA(){
return a;
}
};
4.
1 point
What is the output of the program (considering 8 bytes for the pointers)


#include &#60stdio.h&#62

int main(){
const char firstname[] = "bobby";
const char* lastname = "eraserhead";
printf("%lu\n", sizeof(firstname) +
sizeof(lastname));
return 0;
}
5.
1 point
Which line is wrong with following piece of code. Both targetP and sourceP are pointer to char string of same length.

while( *sourceP ) { // line 1
*targetP = *sourceP ; // line 2
++targetP; ++sourceP ; // line 3
}
*targetP = '\0' ; // line 4
6.
1 point
Which of the line would be reported as errors

int main(int argc, char** argv){

const char* foo = "wow"; // line 1
foo = "top"; // line 2
foo[0] = 1; // line 3

return 0;
}
7.
1 point
What is the output of following program

#include &#60stdio.h&#62
#include &#60string.h&#62
#include &#60stdlib.h&#62
void myfunc(char** param){
++param;
}
int main(){
char* string = (char*)malloc(64);
strcpy(string, "hello_World");
myfunc(&string);
myfunc(&string);
printf("%s\n", string);
// ignore memory leak for sake of quiz
return 0;
}
8.
1 point
What is the output of following program

#include &#60stdio.h&#62
class A
{
int a;
public:
A(){ }
virtual void printA(int a_in = 10) {
printf(" A %d",a_in);
}
};

class C
{
public:
int a;
C (int in) {a = in;}
};

class B : public A
{
public:
virtual void printA(const C &obj)
{
printf(" B %d",obj.a);
}
};

int main()
{
int a = 10;
C b(2);

A obj;
B obj1;
A *obj2 = new B;

obj.printA(a);
obj1.printA(a); // line 1
obj1.printA(b); // line 2
obj2->printA(a); // line 3
obj2->printA(b); // line 4
return 0;
}
9.
1 point
What is the output of following program

#include &#60stdio.h&#62
int main()
{
int count=10,*temp, num=0;
temp=&#38count;
*temp=20;
temp=&#38num;
*temp=count;
printf("%d %d %d ",count,*temp,num);

return 0;
}
10.
1 point
What is the output of the following program

#include &#60stdio.h&#62
class A
{
int a,b;
public:
A(int in, int in1 = 2)
{
a = in1;
b = in;
}
};
class B
{
int a;
A obj;
public:
B(int in){ a = in;}
int getA(){return a;}

}
int main()
{
B obj(5);
printf("%d\n", obj.GetA());
return 0;
}
11.
1 point
What is the output of following code

#include &#60stdio.h&#62
class A
{
int a;
public:
A(){ }
virtual void printA(int a_in = 10) {
printf(" A %d",a_in);
}
};

class B : public A
{
public:
virtual void printA(int a_in = 20)
{
printf(" B %d",a_in);
}
};

int main()
{
A obj;
B obj1;
A *obj2 = new B;
obj.printA();
obj1.printA();
obj2->printA();

return 0;
}
12.
1 point
What will be the output of following code

#include &#60stdio.h&#62
class A{
int a;
public:
int print(int in)
{
printf("Hello World %d\n",in);
}
};

int main()
{
A *obj = NULL;
obj->print(4);

return 0;
}