C question -- Know the answers to the following

M

mluvw47

Know the answers to the following?

Line Contains

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 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. How, exactly, could one get a second 'char*' to use back from
this function? Be specific in terms of the exact syntax needed. (That
is, provide code.) Another way to state this question is how can this
function be modified to return a 'char*' (that is, it maintains the
same return type) from the function, and an additional 'char *' value
in one function call. Please make sure that your answer will work even
if the size of the char * desired is not known in the outside calling
function. Avoid (do no use) C++ syntax. Include statement in called and
calling functions. Use food programming practice.



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 would
you find how many genes are on each and every clone? Please provide the
SQL.



10. What's the difference between system calls and library functions?
 
S

Skarmander

Know the answers to the following?
<snip>
Yes. Except 5, since that's not a question.

Do you? If not, better study harder.

I will say the questions provided are pretty stupid. I'd think twice
before going to work or study at a place giving such examinations.

S.
 
J

John Bode

(e-mail address removed) wrote:
[obvious homework questions snipped]

In the future, if you want help with your homework, it would be best
not to cut and paste the assignment verbatim, and you should have at
least *tried* to answer the questions on your own.

If you do not understand any of the questions, or if you would like us
to comment on your answers, feel free to ask for help. But do not
expect us to do your homework for you.
 
N

Nick Keighley

Know the answers to the following?

Line Contains

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?

<snip>

If you really posted your homework verbatim, then I think the setter
should fail the exam.


--
Nick Keighley

"To every complex problem there is a simple solution...
and it is wrong"
-- Turski
 
S

Skarmander

Nick said:
Know the answers to the following?

Line Contains

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?


<snip>

If you really posted your homework verbatim, then I think the setter
should fail the exam.
The answer, of course, being "nasal demons, unless hell has frozen over
and they're all at the ice rink".

Alternatively, "it's not line 201 that should be executed, it's you, and
your compiler has the right to do so".

S.
 
E

Eric Sosman

Know the answers to the following?

Yes.
Line Contains

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?

1a: Line 201 will not be executed. 1b: Because of
(1a), "under all conditions" it is meaningless to speak
of the value of `q'.
2. Is there an alternative, but equivalent, way to write line
2000? If so, what is it?

2a: Yes. 2b: The words "is it" betray a lack of
understanding of C, and should be replaced by "are they."
3. Is getbuf() a reasonable function?

No. C has no notion of "reason" or "reasonable" or
"reasonability."
4. Will getbuf() execute at all?

No.
5. Please comment on line 2051.

It's shorter than "War and Peace."
6. Is getbuf() good practice, and why?

6a: No. 6b: Because it's bad practice.
7. What line not given should be provided for compilation?

Once again, the use of the singular instead of the
plural shows that the questioner doesn't know C. Alternate
answer: "cc filename.c".
8. How, exactly, could one get a second 'char*' to use back from
this function? Be specific in terms of the exact syntax needed. (That
is, provide code.) Another way to state this question is how can this
function be modified to return a 'char*' (that is, it maintains the
same return type) from the function, and an additional 'char *' value
in one function call. Please make sure that your answer will work even
if the size of the char * desired is not known in the outside calling
function. Avoid (do no use) C++ syntax. Include statement in called and
calling functions. Use food programming practice.

Which function? Also, how can the size of a `char*' be
unknown, anywhere, since it's always `sizeof(char*)'? Finally,
how hungry was the person who wrote the question?
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 would
you find how many genes are on each and every clone? Please provide the
SQL.

Off-topic.
10. What's the difference between system calls and library functions?

Library functions exist, system calls do not.
 
K

kleuske

(e-mail address removed) schreef:
Know the answers to the following?

Ok. I'll play...

<snip all my answers>

Ok. i played. It was simple. It was simple, too, to realize i'm doing
your homework.
 
M

mluvw47

Here is my answer is that correct?
1. What will be in variable 'q' after line 201 is executed? Under what
conditions might this not be so?



aln >> content of b, of which is probably garbage. under some weird
circumstances (eg, snippit within a func that doesn't do garbage
collection and loops around) b might be last known value. if this was
java, i think b might get init to null automagically.



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



aln >> int get_string(char *buff)



3. Is getbuf() a reasonable function?



aln >> i think so but the answer is probably not because of something
to do with a non-static array being casted as a string ptr, right?



4. Will getbuf() execute at all?



aln >> probably not; intuition not based on logical understanding of c
but on "feel" of questions from 3) thru 6).



5. Please comment on line 2051.



aln >> casting to char * for local array probably wont show anything at
all; content only avail w/in scope of func, right?



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



aln >> see 5) above.



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



aln >> dont know.



8. How, exactly, could one get a second 'char*' to use back from this
function? Be specific in terms of the exact syntax needed. (That is,
provide code.) Another way to state this question is how can this
function be modified to return a 'char*' (that is, it maintains the
same return type) from the function, and an additional 'char *' value
in one function call. Please make sure that your answer will work even
if the size of the char * desired is not known in the outside calling
function. Avoid (do no use) C++ syntax. Include statement in called and
calling functions. Use good programming practice.



aln >> no idea...



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 would you find how
many genes are on each and every clone? Please provide the SQL.



aln >> yikes i dont remember anything i learned (and haven't used in) 6
years ago!!!



10. What's the difference between system calls and library functions?



aln >> 1st attempt a: system calls is invoked at runtime when applic
func is called. library functions are incorp into object as defined and
referenced func calls and ck'ed at compile time; ie, lib functions
exists in object code, whereas sys calls are (may be?) undefined?

2nd attempt b: sys call affects os (eg, lo level kernel stuff routines)
whereas lib func may act as liason between app and sys call else just
another func call to existing library of common routines. eg printf is
libr func and the content of printf has sys calls...
 
R

RecruitC++

Greetings, (e-mail address removed)
I am the hiring manager for the C assessment that you so bold
displayed on the internet and FYI I will be removing your candidac
from our application process as you are obviously not qualified fo
this position as you are unable to answer questions by yourself. Mora
of the story...remember you're using the INTERNET DUH!:
 
A

appletree

hi there, if u have the answers for those questions would u mind to
share with me, i have my, and not sure if they are right, so msg me if
u want see my answers.
 
M

Mark F. Haigh

(e-mail address removed) wrote:

Use food programming practice.


/* Example of poor food programming */
char izo_burrito, and_a;
double tequila, please;
(void) bowels();


Is that the right answer? What did I win?


Mark F. Haigh
(e-mail address removed)
 
K

Keith Thompson

appletree said:
hi there, if u have the answers for those questions would u mind to
share with me, i have my, and not sure if they are right, so msg me if
u want see my answers.
Know the answers to the following?

Line Contains

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?
Bits.
what conditions might this not be so?

If the program is run on a trinary computer.

"line MM"

It's eminently reasonable; after all, it has no arguments.

Never. It's morally opposed to the death penalty. (This is a trick
question; if you haven't met getbuf() personally, you probably won't
know this.)


I really like the monospaced font.

It's undoubtedly good practice for something.

"Hey, baby, do you compile around here often?"

return (char*) buff + 'char*'; /* with a side order of onion rings */
SQL://ACACACATCAGCATATCCAACACAAGAATTGGGCACACGTAA/

3.7 microseconds. Less on newer CPUs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top