Total members 10249 | Gratitudes |It is currently Thu May 17, 2012 8:08 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 2 posts ] 
Author Question
 Question subject: how o/p is 1
PostPosted: Thu Sep 08, 2011 7:51 am 

main()
{
int c;
c=-2&&3&&1;
printf("%d",c);
getch();
}

its o/p is 1 how?


TOP
  
Reply with quote  
 Question subject: Re: how o/p is 1
PostPosted: Thu Sep 08, 2011 7:18 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2272
Location: Earth
Has thanked: 39 time
Have thanks: 61 time
First i want to remind you of two things :
First ll and && are logical operators , their results can be 1 (true) or 0 (false) , and you are using it on numbers
http://publib.boulder.ibm.com/infocente ... ogande.htm

Second negative numbers in C++ is represented in 2's complement form.
For example (If we assume for simplicity using 1 byte)
-2 ==>-( 00000010)=11111101+1=11111110

using bit-wise operators like and & and | show different results :
Code:
#include<iostream>
#include<conio.h>
using namespace std;

void main()
{
int c;
c=(-2)&(3)&(1);
printf("%d",c);
getch();
}
 

11111110 AND 00000011 AND 00000001 = 00000000
the results is 0 not 1 .

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 2 posts ] 
Quick reply


  

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team