# questions

This is a discussion on questions within the C Programming forums, part of the General Programming Boards category; 1 Code: for (d = 2; d < p; d++) if (!(p%d)) isPrime = 0; what does the '!' in ...

1. ## questions

1
Code:
```for (d = 2; d < p; d++)
if (!(p%d))
isPrime = 0;```
what does the '!' in the 'if' statement means?

2. What is printed out by the following poorly indented C code fragment?
Code:
```int x = 5, y = 0;
if(x < 3)
if(y > 4)
if (x < 5)
y++;
else
y--;
printf("%i\n", y)```
Why is the ans zero? shouldn't it be 1?

TIA.

2. 1) It's called the NOT operation:
!1 == 0
!0 == 1

2) Why do you think it should be 1? Explain in detail.

3. Originally Posted by Sebastiani
1) It's called the NOT operation:
!1 == 0
!0 == 1

2) Why do you think it should be 1? Explain in detail.
Sorry, not 1, i thought y-- will be carried out instead so it should be -1 right?

4. Why do you think y-- will be carried out?

5. Originally Posted by tabstop
Why do you think y-- will be carried out?
since all the if statements isn't true and the else statement will be carried out?

sigh, my concept still ain't good.

6. Why do you think all the if statements will even be checked?

7. Originally Posted by tabstop
Why do you think all the if statements will even be checked?
ok so ur saying the entire if else statement will all be truncated, and the initial value of y is printed instead?

8. I don't know if I like the word truncated here, but maybe. Think about how if works: you have "if", then you have a condition in parentheses, and then the next complete statement (or block of statements, if we start off with a curly brace) is done when the condition is true. So for that first if-statement, ask: what is the first complete statement following that condition?

9. This screams for indention. . . Indent it the way you think it branches (we'll tell you whether you're correct), then you'll understand.

 Or, tabstop can just spoon feed you.

Popular pages Recent additions