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


Please Help Members By Posting Answers For Below Questions

Which c++ compiler is best?

686


What are the rules for naming an identifier?

666


Why main function is special in c++?

755


What are the various compound assignment operators in c++?

628


What is the extension of c++?

604






If you want to share several functions or variables in several files maitaining the consistency how would you share it?

649


What are the general quetions are in DEna bank manager IT/System interviews?

1647


Reverse the Linked List. Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL

443


What is a container class?

709


What is the difference between the compiler and the preprocessor?

720


Why is swift so fast?

717


What is format for defining a structure?

681


Explain the different access specifiers for the class member in c++.

633


Why do we use constructor?

712


What are the operators in c++?

757