C Inteview Question

Labels: , , |

Question :: Read below code and answer the following 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?
Answer:


2. Is there an alternative, but equivalent, way to write line 2000? If so, what is it?
Answer:



3. Is getbuf() a reasonable function? 
Answer:



4. Will getbuf() execute at all?
Answer:



5. Please comment on line 2051.
Answer:



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



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



(Suggestions and comments are welcome)

0 comments: