Solved

Very basic C question

Posted on 2004-08-04
2
668 Views
Last Modified: 2012-05-05
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.
0
Comment
Question by:deepthiji
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 11722276
>>Could anyone explain to me how the complier end up with this output. i think i know how the
>>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.
0
 
LVL 3

Author Comment

by:deepthiji
ID: 11722299
Thanks a lot, That was quick
points for you and hope the same help in the future.
thanks once again for the help.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to setup iphone app subscription service 3 119
Inorder binary search tree 5 158
Acrinis True image 2 58
gdb doesn't stop on breakpoint 2 50
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

910 members asked questions and received personalized solutions in the past 7 days.

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

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now