By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,332 Members | 1,506 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,332 IT Pros & Developers. It's quick & easy.

help please

P: n/a
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?

Dec 12 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Can anyone suggest me a good link for pointers and memmory management??
Thanks

Dec 12 '05 #2

P: n/a
ch*******@yahoo.com wrote:
[homework questions]


A good many of these are covered in the comp.lang.c
Frequently Asked Questions (FAQ) list at

http://www.eskimo.com/~scs/C-faq/top.html

Begin your studies there.

--
Eric Sosman
es*****@acm-dot-org.invalid
Dec 12 '05 #3

P: n/a
"ch*******@yahoo.com" <ch*******@yahoo.com> writes:
[...]
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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Dec 12 '05 #4

P: n/a
"ch*******@yahoo.com" wrote:

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:Th*************@gmail.com>

Dec 12 '05 #5

P: n/a
<ch*******@yahoo.com> wrote:
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>
Dec 12 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.