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



int f() { int I = 12; int &r = I; r += r / 4; int *p = &r; *p ..

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

int f() { int I = 12; int &r = I; r += r / 4; int *p = &r; *p ..

Answer / guest

ans: 30 i.e 'e'

Is This Answer Correct ?    9 Yes 0 No

Post New Answer

More C++ General Interview Questions

Why is c++ so fast?

0 Answers  


Is c++ slower than c?

0 Answers  


What is the difference between a "copy constructor" and an "assignment operator" in C++?

0 Answers   Genpact,


What do you mean by persistent and non persistent objects?

1 Answers  


Can a constructor throw a exception? How to handle the error when the constructor fails?

1 Answers  






How can you say that a template is better than a base class?

0 Answers  


Can we use this pointer in a class specific, operator-overloading function for new operator?

0 Answers  


What programming language should I learn first?

0 Answers  


What is the syntax for a for loop?

0 Answers  


advantages and disadvantages of using Borland C++ / version 5.

1 Answers  


What is a mutex and a critical section.Whats difference between them?How do each of them work?

4 Answers   CTS,


I want explanation for this assignment: how to connect mysql database using c/c++,please explain this detailly?

0 Answers  


Categories