C++ parameter passing queries (code examples and outputs included)

后端 未结 1 649
北荒
北荒 2021-01-26 15:45

Again here i am because the course material for C++ was not taught very well at all. The question gives use several function definitions and calls to these functions and expects

相关标签:
1条回答
  • 2021-01-26 16:42

    Edit: (based on some commenter feedback)

    Everything you have is mostly correct, save some confusion on your output values. However, what you have in #4 and #5 is actually not overwritten data, it's actually new data at a new address, which is assigned to the variable i. This is part of what an earlier commenter said about a potential for a memory leak. Since you're not deleting the old address before assigning a new one, that's where it could occur.

    The &* syntax in the last one is a reference to a pointer. It's essentially the same as int** except you don't pass &a as the argument, it's just a

    What you have there for number 5 is basically correct, but the reasoning behind it is missing the meaning of &*

    You might want to clarify if you've run each of these function calls sequentially or one at a time, since your output is incorrect if you'd indeed run them sequentially as written.

    0 讨论(0)
提交回复
热议问题