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
Answers were Sorted based on User's Feedback
Answer / 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 |
Why do we use structure in c++?
What does extern mean in a function declaration in c++?
What are the differences between a struct in C and in C++?
if int1 has the value 12, int has the value 18, and int3 has the value 21, what is the result: int1 < int2 && int2 < int 3
What is c++ and its uses?
advantages and disadvantages of using Borland C++ / version 5.
Can we define a constructor as virtual in c++?
What do you mean by vtable and vptr in c++?
What does it mean to declare a member function as virtual?
why is c++ called oops? Explain
What is iterator in c++?
Can c++ do everything c can?