c**********e 发帖数: 2007 | 1 I am declaring a function with a char pointer as input, or no input
int func(char *in="new");
Is it the right way to do it? Any better way to do it? Thanks.
Use CC, I got a warning. |
w***y 发帖数: 78 | 2 "new" is a constant so you'd better declare func as
int func(const char *in = "new"); |
c**********e 发帖数: 2007 | 3 But in general, the input is not constant.
【在 w***y 的大作中提到】 : "new" is a constant so you'd better declare func as : int func(const char *in = "new");
|
w***y 发帖数: 78 | 4 If your func modifies the content of the string, then it is incorrect to
provide a constant default parameter.
If your func does not modify the content of the string, then it doesn't hurt
to declare the parameter as constant. Your func will still happily accept a
non-constant char *. |