&& not working as expected

I'm writing a program that is parsing a file with two pointers, stopping when the "contents" at those pointers become certain values, incrementing the pointers in a while loop otherwise.

My code doesn't seem to work as expected, the problem seems to be that I don't understand the && operator, although I thought I did for the longest time getting results as I expected, although that was using GCC on Linux system.

I am now trying lcc on windows.

I've written some simple code that replicates my problem in understanding:

So when I run the code above I would expect the while loop to run infinitly ( not that I want it too) because a== 5 and b==6 never happens at the same time. However, when I run the program it exits the loop when a == 5, as evidenced(tested) with my printf. So it seems to me that when a == 5 the && is acting like an OR operator " || "; that it will leave the loop if only one of the conditions are met.

I'm writing a program that is parsing a file with two pointers, stopping when the "contents" at those pointers become certain values, incrementing the pointers in a while loop otherwise.

My code doesn't seem to work as expected, the problem seems to be that I don't understand the && operator, although I thought I did for the longest time getting results as I expected, although that was using GCC on Linux system.

I am now trying lcc on windows.

I've written some simple code that replicates my problem in understanding:

So when I run the code above I would expect the while loop to run infinitly ( not that I want it too) because a== 5 and b==6 never happens at the same time. However, when I run the program it exits the loop when a == 5, as evidenced(tested) with my printf. So it seems to me that when a == 5 the && is acting like an OR operator " || "; that it will leave the loop if only one of the conditions are met.

B will never = 6 ... you're starting at 3 and adding 2 each time... 3, 5 ,7 .... so that part of the while loop condition does nothing.

The loop exits on a = 5 because it is no longer true that a is not 5 AND b is not 6... only one of the two required states is true... the loop exits.

I'm writing a program that is parsing a file with two pointers, stopping when the "contents" at those pointers become certain values, incrementing the pointers in a while loop otherwise.

My code doesn't seem to work as expected, the problem seems to be that I don't understand the && operator, although I thought I did for the longest time getting results as I expected, although that was using GCC on Linux system.

I am now trying lcc on windows.

I've written some simple code that replicates my problem in understanding:

So when I run the code above I would expect the while loop to run infinitly ( not that I want it too) because a== 5 and b==6 never happens at the same time. However, when I run the program it exits the loop when a == 5, as evidenced(tested) with my printf. So it seems to me that when a == 5 the && is acting like an OR operator " || "; that it will leave the loop if only one of the conditions are met.

the condition in the while loop states that while "this" condition is true the loop will continue. and a && operator states that while both the conditions are simultaneously true the while loop continues .
so, the condition

Code:

while( (a != 5) && (b != 6) ) )

states that while the value of a is not equal to 5 and SIMULTANEOUSLY the value of b is not equal to 6the loop will continue. if both of them becomes false or even if any one of them becomes false the while loop ends.
so , when the value of a becomes 5 ,(a!=5) becomes false and the while loop ends. and you get the value of a as 5 and b as 9.
and one more thing the return type of main is not void it's int.http://faq.cprogramming.com/cgi-bin/...&id=1043284376