Test Series - cpp

Test Number 7/102

Q: Which of the following is the scope resolution operator?
A. .
B. *
C. ::
D. ~
Solution: :: operator is called scope resolution operator used for accessing a global variable from a function which is having the same name as the variable declared in the function.
Q: Which of the following operator has left to right associativity?
A. Unary operator
B. Logical not
C. Array element access
D. addressof
Solution: Array element has left to right associativity i.e. expressions are evaluated from left to right in case of array element access.
Q: Which of the following is accessed by a member function of a class?
A. The object of that class
B. All members of a class
C. The public part of a class
D. The private part of a class
Solution: A member function of a class can access all the members of its class whether they are private, protected or public.
Q: What is the size of a character literal in C and C++?
A. 4 and 1
B. 1 and 4
C. 1 and 1
D. 4 and 4
Solution: The size of a character literal is 4 in case of C but it is one in case of C++. You can do printf(“%d”, (int)sizeof(‘a’)); in both C and C++ to check this.
Q: What is the size of a character type in C and C++?
A. 4 and 1
B. 1 and 4
C. 1 and 1
D. 4 and 4
Solution: The size of a character type in both C and C++ is 1. You can do printf(“%d”, (int)sizeof(char)); in both C and C++ to check this.
Q: Which of the following is correct?
A. struct tag is required in both C and C++ while declaring an object of the structure
B. struct is not required in C but required in C++ while declaring an object of the structure
C. struct is not required in C++ but required in C while declaring an object of the structure
D. struct tag is not required in both C and C++ while declaring an object of the structure
Solution: C++ does not require struct keyword while declaring an object of the structure whereas in C we require struct tag for declaring an object.
Q: Which of the following is correct?
A. struct cannot have member function in C but it can in C++
B. struct cannot have member function in C++ but it can in C
C. struct cannot have member function in both C and C++
D. struct can have member function in both C and C++
Solution: struct can have member function in C++ whereas member functions are not allowed in case of C.
Q: Which of the following statement is correct?
A. Structure in C allows Constructor definition
B. Structure in C++ allows Constructor definition
C. Both allow Constructor definition
D. C allows constructor definition while C++ does not
Solution: As C does not allow the programmer to define a function inside a structure and constructor itself is a function, therefore, the constructor definition is not allowed in C whereas such definitions are allowed in C++.
Q: Which of the following is correct about this pointer in C++?
A. this pointer is passed as a hidden argument in all the functions of a class
B. this pointer is passed as a hidden argument in all non-static functions of a class
C. this pointer is passed as a hidden argument in all static functions of a class
D. this pointer is passed as a hidden argument in all static variables of a class
Solution: As static functions are a type of global function for a class so all the object shares the common instance of that static function whereas all the objects have there own instance for non-static functions and hence they are passed as a hidden argument in all the non-static members but not in static members.
Q: Which of the following operator is used with this pointer to access members of a class?
A. .
B. !
C. ->
D. ~
Solution: this pointer is a type of pointer and as we know pointer object uses the arrow(->) operator to access the members of the class, therefore, this pointer uses -> operator.

You Have Score    /10