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

Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.

4 Answers   Webyog,


What is difference between c++ 11 and c++ 14?

0 Answers  


What is c++ best used for?

0 Answers  


Why do we learn c++?

0 Answers  


How does a copy constructor differs from an overloaded assignment operator?

0 Answers  


Which is better c++ or java?

0 Answers  


What is a dangling pointer in c++?

0 Answers  


Does c++ have arraylist?

0 Answers  


Define precondition and post-condition to a member function?

1 Answers  


What is a class template in c++?

0 Answers  


What is auto type c++?

0 Answers  


What are c++ templates used for?

0 Answers  


Categories