由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - how to access a const char array in a function
相关主题
问一个精华区里的题目a MS interview question about C++
G家电面,这回肯定挂了。附面经。请教一道c/c++题 (转载)
今天G家电面的一道题问一个memory allocate/release的问题
请问如何准备C/C++面试请教大家一道关于c++的面试题
请问strcpy()和memcpy()的写法问题Thread safe strcpy ??
请问这样写程序错了吗?放c code求老师傅指教
Facebook phone screen[合集] bloomberg面试教训
分享A公司面经一个基本的string问题
相关话题的讨论汇总
话题: const话题: char话题: access话题: array话题: function
进入JobHunting版参与讨论
1 (共1页)
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.

1 (共1页)
进入JobHunting版参与讨论
相关主题
一个基本的string问题请问strcpy()和memcpy()的写法问题
请教operator const char*() 的问题请问这样写程序错了吗?
1道brianbench 的题 c++Facebook phone screen
这小段code有什么问题吗?分享A公司面经
问一个精华区里的题目a MS interview question about C++
G家电面,这回肯定挂了。附面经。请教一道c/c++题 (转载)
今天G家电面的一道题问一个memory allocate/release的问题
请问如何准备C/C++面试请教大家一道关于c++的面试题
相关话题的讨论汇总
话题: const话题: char话题: access话题: array话题: function