C & C++ Programming Multiple Choice Questions - Set 38

1.       The value of an automatic variable that is declared but not initialised will be
(A) 0
(B) -1
(C) unpredictable
(D) none of these
Answer: C
2.       Consider the following program
main ( )
{ float a = 0.5, b = 0.7;
if (b < 0.8)
if (a < 0.5) printf (“ABCD”);
else printf (“PQR”);
else printf (“JKLF);
}
The output is
(A) ABCD
(B) PQR
(C) JKLF
(D) None of these
Answer: B
Explanation:
Since b=0.7<0.8, the control goes to second “if” statement where (a<0.5) is false to printf statement in else part executed printing “PQR”
3.       The following program fragment
int *a;
*a = 7;
(A) assigns 7 to a
(B) results in compilation error
(C) assigns address of a as 7
(D) segmentation fault
Answer: D
4.       A pointer variable can be
(A) passed to a function as argument
(B) changed within function
(C) returned by a function
(D) assigned an integer value
Answer: C
5.       If we store the address of a derived class object into a variable whose type is a pointer to the base class, then the object, when accessed using this pointer.
(A) continues to act like a derived class object.
(B) Continues to act like a derived class object if virtual functions are called.
(C) Acts like a base class object.
(D) Acts like a base class, if virtual functions are called.
Answer: B

6.       Which of the following declarations are illegal?
(A) void *ptr;
(B) char *str = “hello”;
(C) char str = “hello”;
(D) const *int p1;
Answer: C
7.       What would be the output of the following program?
int main()
{
int x,y=10,z=10;
x = (y = = z);
cout<<x;
return 0;
}
(A) 1
(B) 0
(C) 10
(D) Error
Answer: A
8.       What is the error in the following code?
class t
{
virtual void print();
}
(A) No error.
(B) Function print() should be declared as static.
(C) Function print() should be defined.
(D) Class t should contain data members.
Answer: A
9.       main() {
printf(“%p\n”, main());
}
(A) Prints the address of main function
(B) Prints 0
(C) Is an error
(D) Is an infinite loop
Answer: A
10.    The << operator is used for
(A) Right shifting
(B) Left shifting
(C) Bitwise shifting
(D) Bitwise complement
Answer: B


Post a Comment

0 Comments