You are not logged in. Please login at to post your questions!


can someone explain me the output of following program

include <stdio.h>

int main(void) { int i=4,j=1,k=0,w,x,y,z; w=i||j||k; x=i&&j&&k; y=i||j&&k; z=i&&j||k; printf("w=%d x=%d y=%d z=%d\n",w,x,y,z); return 0; }

asked 15 Sep '17, 14:21

arushi_1999's gravatar image

accept rate: 0%

Please use sites like ideone to keep a good format to the code. For now its quite a small code so its readable.

Here, the thing is that in C++, 0 is false and every nonzero value is true. || is an operator that returns true if any of the operands is true and && is an operator that returns false if any one of the operands is false. So. w=i||j||k will set w's value to be 1(true) because both i and j is true(4 and 1 respectively). Similarly, x will become 0, y will become 1(&& is executed before ||) and z becomes 1. So, w, y and z are 1 and x is 0.

Hope this helps :)


answered 15 Sep '17, 19:26

ista2000's gravatar image

4★ista2000 ♦
accept rate: 20%

what if value of j is -1?

(16 Sep '17, 12:14) arushi_19990★

If the value of j=-1, then also you will get same answer. The thing matters here is, value 0. Any non-zero value will be equivalent Boolean 1. So -1 also implies Boolean 1.


answered 16 Sep '17, 12:51

vichitr's gravatar image

accept rate: 11%

toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 15 Sep '17, 14:21

question was seen: 271 times

last updated: 16 Sep '17, 12:51