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
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 |
How does code-bloating occur in c++?
Copy Linked List using recursive function?
What does count ++ do in c++?
How much do c++ programmers make?
Do you know what is overriding?
What is the full form of dos?
Can non-public members of another instance of the class be retrieved by the method of the same class?
simple c++ program for "abcde123ba" convert "ab321edcba" with out using string
Define a pointer to a data member of the type pointer to pointer?
Write a program using shift_half( ) function to shift the elements of first half array to second half and vice versa.
write a program that a 5 digit number and calculates 2 power that number and prints it.
2 Answers Vimukti Technologies,
A milk carton can hold 3.78 litres of milk. Each morning, a dairy farm ships cartons of milk to a local grocery store. The cost of producing one litre of milk is $0.38, and the profit of each carton of milk is $0.27. Write a C++ program that prompts the user to enter the total amount of milk produced in the morning. Then display the number of milk cartons needed to hold milk, the cost of producing milk, and the profit for producing milk.