It's UWAweek 51

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 7 articles in this topic
Showing 7 of 835 articles.
Currently 6 other people reading this forum.


 UWA week 34 (2nd semester, week 5) ↓
SVG not supported

Login to reply

👍x1
helpful
4:55pm Mon 19th Aug, ANONYMOUS
✅ content verified by our teaching staff  

N is replaced with "10;" - so the syntax becomes valid.. for(int i=0; i<10; ++i)


SVG not supported

Login to reply

👍x1
helpful
4:55pm Mon 19th Aug, Christopher M.

ANONYMOUS wrote:
> When you say both your points, are you saying that `for(int i=0 ; i<N ++i){` *is* valid syntax?
It's certainly an error if you correctly perform the textual substitution for N . A couple of students have asked if this is a trick question - not really, misunderstandings about how the preprocessor works are reasonably common.


SVG not supported

Login to reply

👍?
helpful
8:13am Wed 21st Aug, ANONYMOUS

How can the answer still be A when line A is valid and line C contains a syntax error?


SVG not supported

Login to reply

👍?
helpful
8:15am Wed 21st Aug, Christopher M.

ANONYMOUS wrote:
> How can the answer still be A when line A is valid and line C contains a syntax error?
Line A is not valid, and line C does not contain a syntax error. Cut-paste-compile the code if you need to.


SVG not supported

Login to reply

👍?
helpful
1:51pm Wed 21st Aug, ANONYMOUS

Wouldn't this mean that A and B are incorrect. Since we define N as 10; // which includes the semicolon. That means for A, Substitution: char array[10;]; The semicolon causes a syntax error here. For B, int x = 2 * 10;; This results in a double semicolon (;;), which is a syntax error. For C, I think that is okay for the semicolon to be before ++i Thanks!


SVG not supported

Login to reply

👍x1
helpful
2:01pm Wed 21st Aug, ANONYMOUS
✅ content verified by our teaching staff  

Not sure if I am correct but the reason why B (int x = 2 * 10;;) is because it would take the second semicolon as an empty statement so it'll be read as int x = 2 * 10; ; which would not affect the program itself but will just look weird and isn't good practice


SVG not supported

Login to reply

👍?
helpful
2:21pm Wed 21st Aug, Christopher M.

ANONYMOUS wrote:
> Not sure if I am correct but the reason why B (int x = 2 * 10;;) is because it would take the second semicolon as an empty statement so it'll be read as > int x = 2 * 10; > ; > which would not affect the program itself but will just look weird and isn't good practice
This is the correct reasoning.

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