Semicolon and some beginner questions.

Hi all,

I got really confused by some of the questions on my homework, for example:
1)
 
  for (a = 1; a <= 10; a++);

Does the semicolon at the end of the "for loop" statement represent a "Null statement"?

According to my understanding, the semicolon represent the "end" or "completion" of a statement, and a NULL represent a return of "0"? So the above code isn't a NULL statement right? I've came across another thread, and someone has stated that:

1
2
3
4
  for (a = 1; a <= 10; a++)
{
       ;   //represent null statement 
}


Isn't both of the above codes the same thing?


Question 2)
Every input value "must" be checked for:
a)Its range/limits
b)Its reasonableness
c)If any zero division error
d)all of the above
e)none of the above

For this question, I chose "d" as the answer....I know "c" is a must, while "a" is somewhat must, but the problem is, i'm not sure if "b" is required.


Sorry for the newby questions, and Thank you all for the help :)
Last edited on
1) It is the null statement. Those two snippets you have posted are identical; both are for loops whose bodies contain only one statement, the null statement. The null statement has nothing to do with the constant "NULL", which is a preprocessor #define to 0.

2) The question really needs to define "must". You can choose not to check for those things, and the program may not work correctly. The program may also work perfectly fine; for example, you could ask the user for their name and print it back to them. If they enter "asdfasdf", that isn't quite reasonable, but it will not break the program, even if it addresses them as "asdfasdf".
ah i see, i got confused between NULL and null statement.
And for the second question...yea...the choices are a bit arbitrary. I hate multiple choice questions like these lol. But ty anyways.
Topic archived. No new replies allowed.