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 static class data?
Do you know the use of vtable?
Name the debugging methods that are used to solve problems?
Write a c program for binary addition of two 8 bit numbers.
Explain the static member function.
Why was c++ made?
What are mutator methods in c++?
Which of the following is not a valid declaration for main() a) int main() b) int main(int argc, char *argv[]) c) They both work
How much do c++ programmers make?
Describe new operator and delete operator?
Differentiate between a copy constructor and an overloaded assignment operator.
What is a pointer how and when is it used?
What is a float in c++?
What does new return if there is insufficient memory to make your new object?
What do you mean by global variables?