hi,
i would like to know if i need to dinamically allocate a string in main before passing it to a function that i have created.
in that function i just read the string and do not change any chat in it.
thank you in advance for the answer
hi,
i would like to know if i need to dinamically allocate a string in main before passing it to a function that i have created.
in that function i just read the string and do not change any chat in it.
thank you in advance for the answer
No, you can pass a pointer to the first element of a fixed size array declared in the main function. What you do need is to be careful to also specify the size of the array so that the string read into that array will not exceed the boundaries of the array.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Given the lack of clarity of your question, the answer is "it depends".
The caller of a function is always responsible for passing information the function needs, in the form it expects. Dynamic memory allocation might be necessary to achieve that or it might not - although your function would have no way of detecting whether a passed string was allocated dynamically or not. It depends on what your function actually does - and you have supplied no useful information whatsoever about that.