Question Locked

I am finding difficulty in answering these questions. Plese help me.

0 helpful
22 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

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------- }

Q1. What will be in variable ?q? after line 201 is executed? Under what conditions might this not be so?

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

Q3. Is getbuf() a reasonable function?

Q4. Will getbuf() execute at all?

Q5. Please comment on line 2051.

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

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

Q8. 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.

9Q. 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.

22 replies

by sumigopi2006

got answers? Please send the answers fot those Questions.

by akbaralerts

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.

suggestion also accepted....plz
any one plz.....help me as soon as passible
this decides my life?

by boxfiddler Hot topic

Not Homework Central.
Check my profile. I'm a teacher. I might be your teacher.
Bwahahaha!

by jdclyde

you might notice the detail of the time stamp..... :p

by boxfiddler Hot topic

doesn't wake up for another hour or so, and needs at least three cups of coffee.
That's my story and I'm sticking to it.

by jdclyde

as I never bothered opening the OP in the first place. :p

ha ha haaa haaa ha!

:D

by rob mekel

the location of them:

Noobyoobywabba, Philippines
and
Land Of Confusion, Michigan

Both locations seem a bit off this planet, to me ;) 0:-)

by jdclyde

Boxies comment that the (L)user might be one of her students.... :p

by rob mekel

that could wel be ... on the other hand ... neil states:
And the location to both of you ...
The only 2 he's posting to are ... yeb ...
you and Boxies :p

Do like the way you're thinking tho :0
a (L)user being Boxies student ... any idea on how long he's her student ;) 0:-)

[i] dang I like that angel, GG pleaing in the past have become very rewarding :x [/i]

by older mycroft

I'd love to figure out just when the concept of 'personal effort for personal gratification' got deleted from the minds of the world's students.

Next thing, they won't even have to make any effort in order to masturbate ...

...oops!

...Too late!! :^0

by rob mekel

are you on ... that it is "too late" to make the effort :0 B-)

by jdclyde

since it is 2 years old, it hardly rates QOTW.

Maybe zombie of the week? :D

This discussion is closed to new replies.