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


 UWA week 33 (2nd semester, week 4) ↓
SVG not supported

Login to reply

👍?
helpful
3:26pm Sat 17th Aug, Manas R.

The question is about the syntax error but initialising N has a syntax error itself. i.e. #define N 10; Does option B, int x = 2 * N; , count as a syntax error?


SVG not supported

Login to reply

👍?
helpful
5:42pm Sat 17th Aug, Christopher M.

"Manas Rawat" <24*0*7*9@s*u*e*t*u*a*e*u*a*> wrote:
> The question is about the syntax error but initialising N has a syntax error itself.
I recommend that you review this statement.


SVG not supported

Login to reply

👍?
helpful
8:12pm Sat 17th Aug, Manas R.

Consider the following code which contains a common error: #define N 10; void function(void) { A) char array[N]; B) int x = 2 * N; C) for(int i=0 ; i<N ++i) { printf("%c\n", array[i] ); } } Which of the following lines contains a syntax error? A. Line A. B. Line B. C. Line C. D. All of A, B, and C. What will be the correct answer?


SVG not supported

Login to reply

👍?
helpful
7:35am Sun 18th Aug, Christopher M.

"Manas Rawat" <24*0*7*9@s*u*e*t*u*a*e*u*a*> wrote:
> What will be the correct answer?
What is *your* thinking on this question. What do *you* believe is the correct answer, and why?


SVG not supported

Login to reply

👍?
helpful
2:37pm Sun 18th Aug, Manas R.

#define N 10; being wrongly initialised, I think all of the above should be the correct answer, as it makes N = 10, resulting in the error in other statements as well.


SVG not supported

Login to reply

👍?
helpful
2:42pm Sun 18th Aug, Manas R.

N 10;**


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

Login to reply

👍?
helpful
6:06am Mon 19th Aug, Christopher M.

"Manas Rawat" <24*0*7*9@s*u*e*t*u*a*e*u*a*> wrote:
> #define N 10; being wrongly initialised, I think all of the above should be the correct answer, as it makes N = 10, resulting in the error in other statements as well.
The #define preprocessor directive, when used as #define pattern1 pattern2, results in all later instances of pattern1 being replaced by pattern2. In this example, N is not a variable, and is not being initialised, but every following use of N is replaced by 10;. You can follow this example by hand, as under test conditions, to find when the pattern 10; now introduces a syntax error in the C code. And because you're not under test conditions, and have access to a compiler, you could have the compiler identify invalid lines. Hope this helps,


SVG not supported

Login to reply

👍?
helpful
2:38pm Thu 22nd Aug, ANONYMOUS

So here is question number 10 for the midsem:

(10) Consider the following code which contains a common error:

  #define N       10;
  void function(void)
  {
A)    char array[N];
B)    int x = 2 * N;
C)    for(int i=0 ; i<N  ++i) {
          printf("%c\n", array[i] );
      }
  }

Which of the following lines contains a syntax error? A. Line A. B. Line B. C. Line C. D. All of A, B, and C.

why is A the correct answer? (according to the answer sheet) I know that #define N 10; is a wrong syntax but that is not what line A is pointing at


SVG not supported

Login to reply

👍?
helpful
5:04pm Thu 22nd Aug, Christopher M.

#define N 10; is not invalid syntax (it's for the preprocessor, not for the C compiler).

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