由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 问一道brainbench上的问题
相关主题
[c++] reference 真得不能bound to a second object 么?问一个 char * 和 char [] 的问题
why int** cannot convert to const int** ?c++ 弱问题:static const char* const 这两个const 分别是什么意思?
a simple C++ questionC++ Q05: pointer to constant variable
请问const myClass &src 和myClass const &src有什么区别?Array in C
谁给解释一下这个c questionRe: VC里面的stl支持是不是很弱?
数组指针的问题strlen怎么实现的
const char *p, is it ok to change p[1] ?请教一个关于字符指针的简单问题
最新某公司onsite面试题 (转载)c++ string 一问
相关话题的讨论汇总
话题: const话题: char话题: standard话题: type
进入Programming版参与讨论
1 (共1页)
h****b
发帖数: 157
1
size_t sizestr(const char *s)
{
const char * const start =s;
while(*s!='\0')
{
s++;
}
return(s-start);
}
which state below is true
1)the proposed return type deviates standard
2)the suggested implementation is incorrect because a differencing
operation is performed on pointer of unlike type
3) C does not support autoincrement for const qualified pointers. the body
of the loop is invalid
4) By the standard of C, the implementation miscalculates the length of
string
Q**g
发帖数: 183
2
1). ptrdiff_t

【在 h****b 的大作中提到】
: size_t sizestr(const char *s)
: {
: const char * const start =s;
: while(*s!='\0')
: {
: s++;
: }
: return(s-start);
: }
: which state below is true

f******y
发帖数: 2971
3
3

【在 h****b 的大作中提到】
: size_t sizestr(const char *s)
: {
: const char * const start =s;
: while(*s!='\0')
: {
: s++;
: }
: return(s-start);
: }
: which state below is true

g**********d
发帖数: 24
4
我也没看出错来。编译的代码运行成功。 请高人指点
B*******g
发帖数: 1593
5
2楼牛人答对了

【在 h****b 的大作中提到】
: size_t sizestr(const char *s)
: {
: const char * const start =s;
: while(*s!='\0')
: {
: s++;
: }
: return(s-start);
: }
: which state below is true

a****l
发帖数: 8211
6
Actually the code is probabily very correct in every way, but the only "problem" is that it might not be doing what the coder "think" it should be doing. On the other hand, the original question did not state what it is supposed to do, so in this case it is hard to say whether anything is wrong with this code.
This is a typical "school" style question, where you would need to guess what is the intention of the question thus choosing the answer.

【在 g**********d 的大作中提到】
: 我也没看出错来。编译的代码运行成功。 请高人指点
1 (共1页)
进入Programming版参与讨论
相关主题
c++ string 一问谁给解释一下这个c question
Is it safe?数组指针的问题
difference between: char** p and char*p[] ??const char *p, is it ok to change p[1] ?
Why does default exception use char *?最新某公司onsite面试题 (转载)
[c++] reference 真得不能bound to a second object 么?问一个 char * 和 char [] 的问题
why int** cannot convert to const int** ?c++ 弱问题:static const char* const 这两个const 分别是什么意思?
a simple C++ questionC++ Q05: pointer to constant variable
请问const myClass &src 和myClass const &src有什么区别?Array in C
相关话题的讨论汇总
话题: const话题: char话题: standard话题: type