**News Alert:**Experts Exchange Confirmed as Safe in Cloudbleed Leak Read More

Solved

Posted on 2004-08-04

hi experts,

i am a student and learnning C by myself, just started .

i wrote a small basic program using logical operators shown below,

int i=4,j=-1,k=0,w,x,y,z;

clrscr();

w=i||j||k;

x=i&&j&&k;

y=i||j&&k;

z=i&&j||k;

printf ("\n w=%d x=%d y=%d z=%d ",w,x,y,z);

i got the output like this. w = 1 ,x= 0, y = 1, z = 1. Could anyone explain to me how the complier end up with this output. i think i know how the logical operators works. I will appreciate if you explain in a simple way since i am novice to C.

i am a student and learnning C by myself, just started .

i wrote a small basic program using logical operators shown below,

int i=4,j=-1,k=0,w,x,y,z;

clrscr();

w=i||j||k;

x=i&&j&&k;

y=i||j&&k;

z=i&&j||k;

printf ("\n w=%d x=%d y=%d z=%d ",w,x,y,z);

i got the output like this. w = 1 ,x= 0, y = 1, z = 1. Could anyone explain to me how the complier end up with this output. i think i know how the logical operators works. I will appreciate if you explain in a simple way since i am novice to C.

2 Comments

>>logical operators works

Sure:

int i=4,j=-1,k=0,w,x,y,z;

w=i||j||k;

The above is a logical "OR", meaning that w will be set to TRUE when either i, j, or k are non-zero

x=i&&j&&k;

This is a logical "AND", which will assign TRUE to x when all i, j and k are non-zero

y=i||j&&k;

That expression will set y to TRUE when either i is non-zero or both j and k are - the precedence or "AND" (&&) is higher than "OR" (||)

z=i&&j||k;

Here, z will be set to TRUE when both i and j are non-zero or either j or k is.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Title | # Comments | Views | Activity |
---|---|---|---|

How to align numbers in C using the %d | 2 | 98 | |

Intel debugger, idb, only seeing .c and .h, but no .f90 | 1 | 329 | |

List out all word | 7 | 295 | |

Constant string is of type char * ? | 7 | 31 |

Join the community of 500,000 technology professionals and ask your questions.