如果谁想锻炼一下脑筋,就来做题:

来源: 怪哉 2009-01-27 08:49:43 [] [博客] [旧帖] [给我悄悄话] 本文已被阅读: 次 (2887 bytes)


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?



4. Will getbuf() execute at all?



5. Please comment on line 2051.



6. Is getbuf() good practice, and why?



7. What line not given should be provided for compilation?







8. Correct the problems with this function, and then extend it so that it also returns a usable array of pointers to some structures.

The extended version of this function should:

a) Maintain the same "char *" return type which returns a pointer to a usable, for storing a “C” string, memory buffer.

b) In addition, also return a usable array of pointers to structures. This array of pointers is of variable and random length, which must be obtained using GetNumberOfSomeSeqsToGenerate(), which is called, ONLY, from within this new extended version of the function.

c) The type of these structures and the function that should be used to get these structures are defined as follows:

typedef struct {
char* name; /* '\0'-terminated C string */
int number;
} SomeSeq;


/* How many structures should be in the returned array
*/
int GetNumberOfSomeSeqsToGenerate(void);

/* Return the next structure (to fill the
* abovementioned array with).
* Caller is responsible for the cleanup of the returned structure
* and all its content. The latter are all allocated in
* dynamic memory.
*/
SomeSeq * GetNextSomeSeq(void);

Do NOT(!) use "C++" syntax.
Use good programming practice, as much as these instructions allow.


8 1/2. Write a function which calls this function, prints out all data returned by it, and makes sure there are no memory leaks.

Do NOT(!) use "C++" syntax.
Use good programming practice, as much as these instructions allow.















9. For those candidates who know SQL: There is a table with gene_ids (‘gid’) and clone_ids (‘cid’). Each gene only resides on a single clone and each clone may contain multiple genes. How do you find how many genes are on each and every clone? Please provide the SQL.



所有跟帖: 

奇怪呢,昨天做了发给他们,还说有的问题答得不完美 -怪哉- 给 怪哉 发送悄悄话 怪哉 的博客首页 (54 bytes) () 01/27/2009 postreply 12:02:12

请您先登陆,再发跟帖!

发现Adblock插件

如要继续浏览
请支持本站 请务必在本站关闭/移除任何Adblock

关闭Adblock后 请点击

请参考如何关闭Adblock/Adblock plus

安装Adblock plus用户请点击浏览器图标
选择“Disable on www.wenxuecity.com”

安装Adblock用户请点击图标
选择“don't run on pages on this domain”