Default values for array arguments

前端 未结 6 790
孤独总比滥情好
孤独总比滥情好 2021-01-04 06:53

Just playing around a little with C++. What I really want to do is to be able to setup a function with default values defined for an array or pointer argument. To keep thing

6条回答
  •  清酒与你
    2021-01-04 07:30

    When you use string literal "abc", it's allocated by compiler somewhere in the memory, and a pointer to its first character is used as default value. So for the compiler the code is like that: void experimentA(char a[3] = 0x12345678);.

    For the second case, the array literal is not allocated by a compiler as a string (which I would see as some inconsistency in the language).

提交回复
热议问题