Statement (I): A friend function and the member functions of a friend class can directly access private and protected data.
Statement (II): A friend function can access private data through the member functions of the base class.
In the light of the above statements, choose the most appropriate answer from the options given below:
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: A. Both Statement I and Statement II are correct
Explanation
Friends get direct access to private/protected members (I). Like any function, a friend can also reach private data through the class's public member functions (II). The keyed answer treats both as correct.More Programming Languages and Computer Graphics questions
- Match List I with List IIList I List II A. Bezier curves I. 3-D objects that have translational/rotational symmetry B. B-Splines II. Fracta…
- What will be the output of the following code?#include <stdio.h> int main() { int a, b, c; a = 0x10; b = 010; c = a + b; printf("%d", c); r…
- A three-dimensional array in C++ is declared as int A[a][b][c]. Array elements are stored in row-major order and indexing begins from 0. Th…
- What is the output of the following code?main() { struct s1 { char *z; int i; struct s1 *p; }; static struct s1 a[] = { {"Nagpur", 1, a+1},…
- The Sutherland-Hodgeman method is used on
- What is x in the following program?#include <stdio.h> int main() { typedef int (*(*arrfptr[3])())[10]; arrfptr x; return 0; }