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
Is swift a good first language?
Difference between a copy constructor and an assignment operator.
Explain operator overloading.
Is there any function that can skip certain number of characters present in the input stream?
which one is equivalent to multiplying by 2:Left shifting a number by 1 or Left shifting an unsigned int or char by 1?
Explain how to initialize a const data member.
Does c++ vector allocate memory?
Do you know what are the new features that iso/ansi c++ has added to original c++ specifications?
What is an iterator class in c++?
Define a pointer to a data member of the type pointer to pointer?
How do you add an element to a set in c++?
What are arrays c++?
When is the destructor called?
Is c++ a software?
Which one is a preferred language C or C++? Why?