C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28645
Number of posts: 94661

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
please explain output of if(x=10) else ??? Posted by nnat on 20 Jul 2011 at 1:11 PM
#include<stdio.h>
#include<conio.h>
int main()
{
int x= 10;
if (x=20) printf("true");
else printf("false");
getch();
}

output is true and x got the value of 20. why x got this value?
Report
Re: please explain output of if(x=10) else ??? Posted by friendlyghost on 21 Jul 2011 at 6:50 AM
i do'nt know what's your knowledge is but if you see your code you will find that with if you used simple equal to sign whereas in c++ for comparison we use double equal to sign & for assigning a value we use simple equal to.
Report
Re: please explain output of if(x=10) else ??? Posted by nnat on 22 Jul 2011 at 7:40 AM
hey, thanks for reply. i'm new at c, dont know much. i am just wondering that since if-else used in decision making and they takes conditional or relational expression but "=" this symbol used for assignment purposes.
it's little confusing at first time that it processed and gives positive output(true)or(1) not (false)or(0) but i understand later that it can process anything and till its getting 1 or 0 its no problem for compiler so to me.
just for knowledge though, what other uncommon expression we can use between these().

Report
Re: please explain output of if(x=10) else ??? Posted by ruxhong on 15 Aug 2011 at 11:50 PM
Thanks for you share
[url=http://cheapcoachoutlet.twoday.net/stories/welcome-discount-coach-outlet/]welcome discount coach outlet[/url]
[url=http://www.coachoutletsell.zoomshare.com/2.shtml]Coach Outlet Cost-effective Output [/url]
[url=http://www.rockinfrnz.com/sellcoachoutlet/blog/custom-products-coach-ouelet/]custom products coach ouelet[/url]

Report
This post has been deleted. Posted by nnat on 22 Jul 2011 at 7:42 AM
This post has been deleted.
Report
This post has been deleted. Posted by nnat on 22 Jul 2011 at 7:44 AM
This post has been deleted.
Report
Re: please explain output of if(x=10) else ??? Posted by friendlyghost on 21 Jul 2011 at 6:52 AM
i do'nt know what's your knowledge is but if you see your code you will find that with if you used simple equal to sign whereas in c++ for comparison we use double equal to sign & for assigning a value we use simple equal to.
Report
Re: please explain output of if(x=10) else ??? Posted by friendlyghost on 21 Jul 2011 at 6:58 AM
the = sing used in if is used to assign the value but for comparison we use ==



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.