It's UWAweek 38 (2nd semester, week 8)

help2002

This forum is provided to promote discussion amongst students enrolled in CITS2002 Systems Programming.
Please consider offering answers and suggestions to help other students! And if you fix a problem by following a suggestion here, it would be great if other interested students could see a short "Great, fixed it!"  followup message.
Displaying the 4 articles in this topic
Showing 4 of 477 articles.
Currently 43 other people reading this forum.


 UWA week 36 (2nd semester, mid-semester break) ↓
SVG not supported

Login to reply

👍?
helpful
9:36am Fri 6th Sep, Etienne VH.

I don't understand why the answer to question 20 was D, rather than C, is anyone able to explain?

Thank you :)

(20) Consider the following C code: * void function(void) { fork(); fork(); printf("hello world\n"); } * If the above code executes successfully, which of the following statements will always be true? A. The output "hello world" will be printed once. B. The output "hello world" will appear exactly twice, on two separate lines. C. The output "hello world" will appear exactly four times, on four separate lines. D. The form of the output cannot be determined from the above code.


SVG not supported

Login to reply

👍?
helpful
10:34am Fri 6th Sep, Amitava D.

"Etienne Vinton Horn" [email protected] wrote:

I don't understand why the answer to question 20 was D, rather than C, is anyone able to explain?

Thank you :)

(20) Consider the following C code: * void function(void) { fork(); fork(); printf("hello world\n"); } * If the above code executes successfully, which of the following statements will always be true? A. The output "hello world" will be printed once. B. The output "hello world" will appear exactly twice, on two separate lines. C. The output "hello world" will appear exactly four times, on four separate lines. D. The form of the output cannot be determined from the above code.

I don't know what Chris had mind, it could be a trick question (note the 'always be true'). Suppose I write a complete C code with a main() and do not call this function?


SVG not supported

Login to reply

👍?
helpful
10:51am Fri 6th Sep, Chenjun H.

I'm not really sure, but I believe the answer is D because the fork() system call doesn't exist on Windows, which is why it isn't guaranteed to work.


SVG not supported

Login to reply

👍?
helpful
4:16pm Fri 6th Sep, ANONYMOUS

well, not really sure about this either, but in my opinion it really comes down to technicality, since after the fork, the code doesn't terminate, so we can either call fork() again somewhere outside the function, or call the function more than one time

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Written by [email protected]
Powered by history
Feedback always welcome - it makes our software better!
Last modified  8:08AM Aug 25 2024
Privacy policy