![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Apr 2005
Posts: 3
Rep Power: 0
![]() |
Need help on a program--- Came to find out it was not a PERL Program!
Hi to all,
I am a QA analyst with 5 years of experience. I would like to get some help on this program. Suggestions or comments would be much appreciated. It is NOT homework, just to reassure you. Thank you 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? 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 not use) C++ syntax. Include statements in called and calling functions. |
|
|
|
|
|
#2 |
|
Professional Programmer
|
That's not even code. Almost like pseudocode. Where'd you get this "project" from?
__________________
Amateurs built the ark Professionals built the Titanic |
|
|
|
|
|
#3 |
|
Professional Programmer
|
lmao...
|
|
|
|
|
|
#4 |
|
Newbie
Join Date: Apr 2005
Posts: 3
Rep Power: 0
![]() |
Help in program.
It is a pseudocode. Any idea. Any input or help would be much appreciated.
Thank you. Ndumbane |
|
|
|
|
|
#5 | |
|
Newbie
Join Date: Apr 2005
Posts: 3
Rep Power: 0
![]() |
Quote:
Thank you. Ndumbane |
|
|
|
|
|
|
#6 |
|
Newbie
Join Date: Apr 2005
Posts: 2
Rep Power: 0
![]() |
Line 2000 is the beginning of the getbuf function definition. It defines the fuction's interface. It means that a function named getbuf will take no parameters (any paramters would be listed inside of the parenthesis) and will return a pointer to a character (char *). Everything between the brackets on lines 2001 and 2052 define what the function does.
We don't really know what it does because lines 2003 through 2050 are missing. However, it doesn't really matter what it does because you are returning a pointer to the address of the first element of an array that only exists within the scope of the getbuf function. Line 2000 creates an array of characters with a length of 8. This array is only valid within the closing brackets of the getbuf function. Line 2051 returns a pointer to the beginning of the array, but it's of no use to the calling program (see Line 200 where getbuf is called) because after the function returns control to the calling program, the array is gone. |
|
|
|
|
|
#7 | |
|
Professional Programmer
|
Quote:
__________________
Amateurs built the ark Professionals built the Titanic |
|
|
|
|
|
|
#8 |
|
Programming Guru
![]() ![]() ![]() |
i agree with piece_of_mind...
besides, I thought you "QA guys" only dealt with the end product?
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|