由买买提看人间百态

topics

全部话题 - 话题: getbuf
(共0页)
c*****o
发帖数: 178
1
来自主题: JobHunting版 - 问个面试的编程题目 (转载)
1. q = b[0]; getbuf() 中没有buff的初始化部分代码。如果没有,q的值不定。
2. 不应该返回localvariable的地址,编译有warning。如果只想得到一个char值,可
以返回buff[]中的具体值。不知道怎么改写,这个返回地址本身就不对。
3. 不是,同2.
4. 可以执行。
5. 同2.
6. 如果一定要修改一个数组的值,不如传数组的reference作为getbuf()的一个
parameter
7. 在主程序里declare引用的函数。在b = getbuf (); 之前:char * getbuf ();
8. void getbuf(char*, char*);
s******e
发帖数: 493
2
来自主题: Programming版 - Anybody help me on these questions?
LINE Contains
50 char * b, q, *r;
200 b=getbuf();
201 q = *b;
212 r= anotherfunction(b);
213-300 /* we want to use ‘q’ and ‘r’ here*/
2000 char * getbuf()
2001 {
2002 char buff[8];
2003-2050 /* unspecified, buff defined here *./
2051 return (char *) buff;
2052 }
1. What will be in variable ‘q’ after line 201 is executed? Under what
conditions might this not be so?
2. Is there an alternative, but equivalent, way to write line 2000? If so,
what is it?
3. Is getbuf() a reasonable function?
T*****J
发帖数: 193
3
来自主题: JobHunting版 - 问个面试的编程题目 (转载)
【 以下文字转载自 Programming 讨论区 】
发信人: ThomasJ (JY), 信区: Programming
标 题: 问个面试的编程题目
发信站: BBS 未名空间站 (Sat Jan 2 23:23:23 2010, 美东)
现场让30分钟做完
50 char *b, q, *r;
200 b = getbuf ();
201 q = *b;
212 R = anotherfunction (b);
213-2003 /* we want to use 'q' and 'r' here */
2000 char * getbuf ()
2001 {
2002 char buff [8];
2003-2050 /* unspecified buff defined here */
2051 return (char*) buff;
2052 }
1. What will be in variable 'q' after line 201 is executed? Under
what conditions might this not be so?
2. Is t
t****t
发帖数: 6806
4
来自主题: Programming版 - Anybody help me on these questions?

basically right. i might add that, since buff[] is on stack, it is very
easy to get destroyed very quickly.
not very sure, probably he means char * getbuf(void)?
I would not call that reasonable. after adding static, it is ok, but still
not very good.
fine
not sure what he want. but 2051 is fine. however you don't need the cast.
probably you need an additional "char* getbuf()" before invoking it,
but it will probably pass the compile.
probably my english is so bad, but i don't understand the
t****t
发帖数: 6806
5
来自主题: Programming版 - Anybody help me on these questions?

basically right. i might add that, since buff[] is on stack, it is very
easy to get destroyed very quickly.
not very sure, probably he means char * getbuf(void)?
I would not call that reasonable. after adding static, it is ok, but still
not very good.
fine
not sure what he want. but 2051 is fine. however you don't need the cast.
probably you need an additional "char* getbuf()" before invoking it,
but it will probably pass the compile.
probably my english is so bad, but i don't understand the
i****t
发帖数: 113
6
来自主题: Programming版 - C++ questions
Can anyone give me some hints on the following questions? Thanks.
50 char *b, q, *r;
200 b = getbuf ();
201 q = *b;
212 R = anotherfunction (b);
213-2003
/* we want to use q and r here */
2000 char * getbuf ()
2001 {
2002 char buff [8];
2003-2050
/* unspecified buff defined here */
2051 return (char*) buff;
2052 }
1. What will be in variable q after line 201 is executed? Under what
conditions might this not be so?
2. Is there an alternative, but equivalent, way to wr
W*******o
发帖数: 301
7
来自主题: Programming版 - 问一道C++的题目。 (转载)
【 以下文字转载自 JobHunting 讨论区 】
发信人: WEKingpro (口味蛇), 信区: JobHunting
标 题: 问一道C++的题目。
发信站: BBS 未名空间站 (Sat Jan 6 21:09:12 2007)
char* getbuf() {
char buff[8]="abcdefg";
return (char*)buff;
}
void main() {
char* b, q;
b = getbuf();
q = *b;
printf("%c\n", q);
}
输出结果中,q除了等于a, 还有可能等于什么?
s*******e
发帖数: 664
8
来自主题: Programming版 - [合集] 问个面试的编程题目
☆─────────────────────────────────────☆
ThomasJ (JY) 于 (Sat Jan 2 23:23:23 2010, 美东) 提到:
现场让30分钟做完
50 char *b, q, *r;
200 b = getbuf ();
201 q = *b;
212 R = anotherfunction (b);
213-2003 /* we want to use 'q' and 'r' here */
2000 char * getbuf ()
2001 {
2002 char buff [8];
2003-2050 /* unspecified buff defined here */
2051 return (char*) buff;
2052 }
1. What will be in variable 'q' after line 201 is executed? Under
what conditions might this not be so?
2. Is there an alternative, but equiv
e********e
发帖数: 12
9
来自主题: JobHunting版 - 问个面试的编程题目 (转载)

must be void getbuf(char**, char**)
k****f
发帖数: 3794
10
来自主题: Programming版 - 问一道C++的题目。 (转载)
buff是在栈里的,退出getbuf,应该就不是有效的
b***y
发帖数: 2799
11
来自主题: Programming版 - [合集] 这样写有什么不好?
☆─────────────────────────────────────☆
topbull (塞猪~最近比较衰) 于 (Tue Oct 18 01:52:00 2005) 提到:
char * getbuf()
{
char buff[8];
....
return (char *)buff;
}
☆─────────────────────────────────────☆
campos (Gentoo 真土) 于 (Tue Oct 18 02:03:46 2005) 提到:
returned pointer contains nothing
accessing it will cause access violation

☆─────────────────────────────────────☆
xingxing (星星) 于 (Tue Oct 18 02:27:39 2005) 提到:
that pointer is just on the stack.
I think most likely there won't
x***y
发帖数: 45
12
来自主题: Programming版 - simple C question
char * b, q, *r;
b=getbuf();
q = *b;
What will be in variable ‘q’? Under what conditions might this not be so?
f*****Q
发帖数: 1912
13
来自主题: Programming版 - simple C question
getbuf是啥?
(共0页)