help please

C

chump1708

line 50 - char *b, q, *r;

line 200 - b = getbuf ();

Line 201 q = *b;

Line 212 R = anotherfunction (b);

Lines 213-2003 /* we want to use 'q' and 'r' here */

Line2000 char * getbuf ()

Line2001 {
Line 2002 char buff [8];

Lines 2003-2050 /* unspecified buff defined here */

Line 2051 return (char*) buff;

Line 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 good programming practice.

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

Keith Thompson

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.
[snip]

I'll give you the standard response: give us your instructor's e-mail
address so we can submit the answers directly.
 
K

Kenneth Brody

line 50 - char *b, q, *r;

line 200 - b = getbuf (); [...]
Line 2051 return (char*) buff;

Line 2052 }

1. What will be in variable 'q' after line 201 is executed?
Under what conditions might this not be so? [...]
9. What's the difference between system calls and library functions?

This exact message was posted, verbatim, back on Oct. 3, under the
subject "C question - Know the answers to the following".

So, either this is a serial drive-by troll, or the result of someone
supposedly teaching C to clueless newbies.

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:[email protected]>
 
O

osmium

line 50 - char *b, q, *r;

line 200 - b = getbuf ();

Line 201 q = *b;

Line 212 R = anotherfunction (b);

Lines 213-2003 /* we want to use 'q' and 'r' here */

Line2000 char * getbuf ()

Line2001 {
Line 2002 char buff [8];

Lines 2003-2050 /* unspecified buff defined here */

Line 2051 return (char*) buff;

You are returning a pointer to an auto array. This is really bad because
it might work, by chance, from time to time. The quick fix is to change
line 2002 to:

static char buff[8];

The proper fix usually is to change the ownership of the array to a higher
level (outer) function.

Why did you provide a (char*) cast on the return statement? Did it fail to
compile without the cast?

Your post is too cryptic to my taste and you try to get *way* too much
information from a single post.
Line 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?

<snip questions 4, 5, 6, 7, 8 and 9>
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top