int f() {
int I = 12;
int &r = I;
r += r / 4;
int *p = &r;
*p += r;
return I;
}
Referring to the sample code above, what is the return value
of the function "f()"?
a) 12
b) 15
c) 24
d) 17
e) 30
Answer Posted / uma sankar pradhan
int I=12;
int &r=I;
here r is a reference to I
r+=r/4;
=>r=r+r/4;
=>r=12+12/4;[r=I=12]
=>r=12+3
=>r=15
=>I=15
int *p=&r;
so, p is a pointer to r(i.e.,to I)
*p +=r;
=>*p = *p+r
=>*p=15+15
=>*p=30
=>I=30
so the return value of the f() is 30
| Is This Answer Correct ? | 15 Yes | 0 No |
Post New Answer View All Answers
What is a local variable?
Show the application of a dynamic array with the help of an example.
When do we run a shell in the unix system?
Which programming language's unsatisfactory performance led to the discovery of c++?
What does flush do?
What is function prototyping?
Difference between struct and class in terms of access modifier.
What do you understand by a pure virtual member function?
What do you mean by inheritance in c++? Explain its types.
What is scope operator in c++?
Can I have a reference as a data member of a class? If yes, then how do I initialise it?
Explain the use of this pointer?
What are inline functions? What is the syntax for defining an inline function?
What is a literal in c++?
What is rtti in c++?