You are here:

C++/c programming




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


Hello 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


All Answers

Answers by Expert:

Ask Experts




I can answer questions about the C++ language, object oriented design and architecture. I am knowledgable in a lot of the math that goes into programming, and am certified by I also know a good deal about graphics via OpenGL, and GUIs.


I have completed numerous games and demos created with the C++ programming language. Currently employed as a software engineer in the modeling and simulation field. I have about 7 years experience.

©2016 All rights reserved.