#include iostreamhvoid subint x int y int z z = y + x;void main int a b c;sub8 4 &a;sub6 a &b;suba b &c;cout a b c endl;
The output of this program is:
12,18,-6
Explanation:
- The function sub() takes in three parameters: x, y, and a pointer to an integer variable z.
- It adds x and y together, and stores the result in the memory location pointed to by z.
- In the main() function, we declare three integer variables: a, b, and c.
- We call sub() three times, passing in different values for x, y, and z each time.
- The first call to sub() sets a to 12 (since 8 + 4 = 12).
- The second call to sub() sets b to 18 (since 6 + a = 6 + 12 = 18).
- The third call to sub() sets c to -6 (since a - b = 12 - 18 = -6).
- Finally, we print out the values of a, b, and c using cout
原文地址: https://www.cveoy.top/t/topic/fffO 著作权归作者所有。请勿转载和采集!