c**y 发帖数: 172 | 1 函数声明如下
void function1(const char *a) {
...
...
return;
}
如何能在函数function1中访问a呢?我只想到用strcpy的方法把a复制到另外一个char
array中。有没有什么办法直接访问a,而不使用额外的内存? | S***n 发帖数: 31 | 2 which do you want to access to? "a" or the object "a" pointing to?
If it's "a", use reference "const char& *a" in the argument
if it's the object "a" pointing to, just access by *a, eg. *(a++).
Personal opinion :) | w***h 发帖数: 415 | 3 Sure not right. *a is const, a is not const.
Why don't you code, compile and run. Just do it first, and think secondly.
My simple advice.
【在 c**y 的大作中提到】 : 函数声明如下 : void function1(const char *a) { : ... : ... : return; : } : 如何能在函数function1中访问a呢?我只想到用strcpy的方法把a复制到另外一个char : array中。有没有什么办法直接访问a,而不使用额外的内存?
| c**y 发帖数: 172 | 4 I am sorry. You are right. Thanks,
【在 w***h 的大作中提到】 : Sure not right. *a is const, a is not const. : Why don't you code, compile and run. Just do it first, and think secondly. : My simple advice.
|
|