C++/c programming
Expert: Eddie - 8/7/2006
Question
-------------------------
Followup To
Question -
please explain the difference between these 2 segments of the C code:
if (a & b)
flag = 0;
else flag = 1;
if (a && b)
flag = 0;
else flag = 1;
Answer -
Hello simon, thank you for the question.
The first segment of code checks if a bitwise "anded" with be is a non zero value and assigns a variable based on the answer. The second segment of code checks to see if both the variables are non zero, like if a and b are both equal to true, and assigns a variable based on the answer.
I hope this information was helpful.
- Eddie
Hi, here's another one for you Eddie.
which of these C statements are wrong syntactically (i.e. would generate a compiler error as the syntax is wrong), and why?
1. int k, h;
2. float k = 0.0 + p;
3. if (n = 4) n = 0;
4. #define MAX 10000*5
5. while (m) { k++; m--}
6. char c, h
thanx
AnswerHello again Simon, thank you for the question.
3 is incorrect. When you check to see if something equals a value, you use 2 equals signs. The correct syntax is:
if (n == 4) n = 0;
Feel free to ask another question if you need clarification on anything else.
- Eddie