a******u 发帖数: 239 | 1 I think my answers to Question 7 and 8 are correct, but they said they are
not correct, why?
I already tested the code by Visual C++ (c compiler).
Thank you very much.
Line in file Contents
30 int * someIDs, theFirst, *r;
110 someIDs =GetSomeIDs(); /* defined below */
111 theFirst = someIDs [0];
112 r= ReorderIDs(someIDs);
113-150 /* we want to use ‘theFirst’ and ‘r’ here*/
499 /*-------- GetSomeIDs-----*/
500 int * GetSomeIDs()
501 {
502 int ids[8];
503-5... 阅读全帖 |
|
i***0 发帖数: 8469 | 2 Line in file Contents
30 int * someIDs, theFirst, *r;
110 someIDs =GetSomeIDs(); /* defined below */
111 theFirst = someIDs [0];
112 r= ReorderIDs(someIDs);
113-150 /* we want to use ‘theFirst’ and ‘r’ here*/
499 /*-------- GetSomeIDs-----*/
500 int * GetSomeIDs()
501 {
502 int ids[8];
503-550 /* The ids are defined here */
551 return ids;
552 }
1. Is GetSomeIDs() a reasonable function?
2. Is there a different way to write line 500 which preserves the same
effective prototype? If so |
|
s*******e 发帖数: 664 | 3 ☆─────────────────────────────────────☆
merriam (爱我所爱,珍惜拥有!) 于 (Sun Jan 3 16:02:31 2010, 美东) 提到:
what the correct int * GetSomeIDs() should be like? Thanks
30 int * someIDs, theFirst, *r;
110 someIDs =GetSomeIDs(); /* defined below */
111 theFirst = someIDs [0];
112 r= ReorderIDs(someIDs);
113-150 /* we want to use ‘theFirst’ and ‘r’ here*/
499 /*-------- GetSomeIDs-----*/
500 int * GetSomeIDs()
501 {
502 int ids[8];
503-550 /* The ids are defined |
|
x***y 发帖数: 633 | 4 There is something unclear about the problem, but I think one possibility is:
Before calling the GetSomeIDs() function, the length of the array of aliasID
pointers is determined and a pointer is passed as a parameter to the
GetSomeIDs() function: ( we can cast p from void * to aliasID** inside the
function)
int* GetSomeIDs(void * p)
Inside this function, we can call int GetNumberOfAliases(void) to get # of
pointers in the array and dynamically allocate memory which will be assigned to each point |
|
f********1 发帖数: 228 | 5 【 以下文字转载自 Programming 讨论区 】
发信人: falcon8241 (falcon), 信区: Programming
标 题: A weird C programming language--Return a pointer to array
发信站: BBS 未名空间站 (Wed May 29 13:54:54 2013, 美东)
A question I encountered during the interview. Could anyone give me some
idea.
The key issue is I was asked to modify line 500, which is the function
declaration...
Is there a different way to write line 500 which preserves the same
effective prototype? If so, what is it?
Line in file
Code:
30 int * someIDs, theFirst,... 阅读全帖 |
|
f********1 发帖数: 228 | 6 A question I encountered during the interview. Could anyone give me some
idea.
The key issue is I was asked to modify line 500, which is the function
declaration...
Is there a different way to write line 500 which preserves the same
effective prototype? If so, what is it?
Line in file
Code:
30 int * someIDs, theFirst, *r;
110 someIDs =GetSomeIDs(); /* defined below */
111 theFirst = someIDs [0];
112 r= ReorderIDs(someIDs);
113-150 /* we want to use ‘theFirst’ and ‘r’ here*/
499 /*--------... 阅读全帖 |
|
e****9 发帖数: 316 | 7 来自主题: JobHunting版 - 问道编程题 代码:
499 /*-------- GetSomeIDs-----*/
500 int * GetSomeIDs()
501 {
502 int ids[8];
503-550 /* The ids are defined here */
551 return ids;
552 }
题目是:
Is there a different way to write line 500 which preserves the same
effective prototype? If so, what is it?
实在想不出有什么别的方式来定义函数,不知道大家有什么建议没有? |
|
a****n 发帖数: 1887 | 8 来自主题: JobHunting版 - 问道编程题 499 /*-------- GetSomeIDs-----*/
500 int * GetSomeIDs()
501 {
502 int ids[8];
503-550 /* The ids are defined here */
551 return ids;
552 }
或者用static, 或者放到heap 里
502 static int ids[8]; |
|
P*******b 发帖数: 1001 | 9 【 以下文字转载自 Programming 讨论区 】
发信人: snowyrose (好好学习天天向上), 信区: Programming
标 题: [合集] C coding problems
发信站: BBS 未名空间站 (Mon Mar 1 13:56:18 2010, 美东)
☆─────────────────────────────────────☆
merriam (爱我所爱,珍惜拥有!) 于 (Sun Jan 3 16:02:31 2010, 美东) 提到:
what the correct int * GetSomeIDs() should be like? Thanks
30 int * someIDs, theFirst, *r;
110 someIDs =GetSomeIDs(); /* defined below */
111 theFirst = someIDs [0];
112 r= ReorderIDs(someIDs);
113-150 /* we want to use ‘theFirst’ an |
|
a**1 发帖数: 213 | 10 只有两个包子了现在。
问题好像被问了很多次了,但没查到答案。谢谢。
这个思路对吗:
int* GetSomeIDs(aliasID*** p_aliasID_io)
怎么用GetNextAlias()? 这个问题说的太不清楚了。
题目是:
Correct the problems with GetSomeIDs(), and add some additional
functionality to it, as follows. A single new version of the function
should be provided.
The new version should:
a) Maintain the same "int *" return type which returns a pointer to fixed
sized array of ints.
b) IN ADDITION to its regular function return, provide to its calling
functions a usable array of poin |
|
x***y 发帖数: 633 | 11 Yes, it's also possible that in the function GetSomeIDS, we assign the array
of pointers some already existing aliasIDS structure, and when exiting from
this function, the call to GetNextAliss will get the next pointer to
aliasID in the array. We can use this method(calling GetSomeIDS and aliasID
iteratively to get all the IDS.) I'm not sure what else are expected....
Then
still |
|
s********g 发帖数: 60 | 12 499 /*-------- GetSomeIDs-----*/
500 int * GetSomeIDs()
501 {
502 int ids[8];
503-550 /* The ids are defined here */
551 return ids;
552 }
不能这么写吧,ids是局部变量,function结束后指针为junk,用heap内存存储才好 |
|
s***5 发帖数: 2136 | 13 int * GetSomeIDs()
{
int ids[8];
/* The ids are defined here */
return ids;
}
Is there a different way to write "int* GetSomeIDs()" which preserves the
same effective prototype? If so, what is it?
Thanks. |
|
t*q 发帖数: 104 | 14 来自主题: JobHunting版 - 问道编程题 const int * GetSomeIDs() ? |
|
e********e 发帖数: 12 | 15 来自主题: JobHunting版 - 问道编程题 500 GetSomeIDs(int **ppids) |
|
j******n 发帖数: 611 | 16 提示一下:
#2 int (*GetSomeIDs())[8] |
|
j******n 发帖数: 611 | 17 #7 提示一下:
int (* GetSomeIDs(aliasID** aID,int * sz))[8]
{
.....
} |
|
f****n 发帖数: 399 | 18 敢问是什么公司?
int * GetSomeIDs(aliasID** aID,int * sz)
这个定义是题目给的还是你自己想的阿? |
|
h**k 发帖数: 3368 | 19 题目要求The length of
this array of pointers is returned by a call to GetNumberOfAliases(), which
you may call only from within GetSomeIDs(). 你可能没注意到。 |
|
f******h 发帖数: 45 | 20 不是很理解问题,什么是effective prototype?
是说改函数里面的内容,返回 *id?
还是说改函数的输入输出?比如说改成这个样子。
void GetSomeIDs(int** id)
{
int ids[8];
/* The ids are defined here */
*id = ids;
return;
} |
|
c******y 发帖数: 14 | 21 这么改?
void GetSomeIDs(int*& x){
int ids[8];
/* The ids are defined here */
x = ids;
} |
|
s*******1 发帖数: 33 | 22 去面试被要求用纯C写程序,不能有C++ syntax,我写的代码如下:
//Assume ids[] is to get specific_id in aliasID
//num is used to fix the length of ids[]
//alias is used to get the aliasID array
//aliasNum is used to get the length of array alias
/*
successFind = ture means return ids[] with length of num
successFind = false means return ids[] is null
or the length of ids[] is aliasNum (num > aliasNum)
*/
int* GetSomeIDs(int num, aliasID* &alias, int &aliasNum, bool& successFind)
{
successFind = true;
... 阅读全帖 |
|
d****n 发帖数: 1637 | 23 #define GetSomeIDs() ( int ret[8]; memcpy(ret, _getSomeIDs()); {ret;} )
int * _getSomeIDs(){
//... previous definition
} |
|
m***x 发帖数: 20 | 24 inline int * GetSomeIDs() |
|