ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Thank you.
I guess c1=i%3 means give the value of i%3 to the variable c1, if add "==0" at the end, what is the meaning of the clause, c1=i%3==0 ?
Another question:
Code:
#include<iostream>
using namespace std;
main()
{
int i;
cout<<1%3==0;
}
The reason the output given is the ans for (1%3) .
The cout takes it that way due to I suppose operator precedence.
If you want entire thing i.e , 1%3==0 , you must enclose them in
brackets i.e , (1%3==0)
The meaning of this clause is (1%3==0) is it checks if the value
of 1%3 is equal to 0 and returns (0 for false, 1 for true)
Ex:- Suppose we say (14%3==0)
14%3 is 2 and it is not equal to 0
So , output will be "0" [False]
Now I want to know why the output of cout<<1%3==0; is 1 instead of some error information?
What is the computer's thinking about the clause, cout<<1%3==0;?
Does the computer consider cout<<1%3==0; as cout<<1;, and ignore %3==0?
Last edited by Xiangbuilder; 09-13-2003 at 03:16 AM.
I feel 14%3 is equal to the integer 2,
does (cout<<14%3) is equal to the integer 2?
does the type of (cout<<i) is same as the type of i?
Why the output of ((cout<<14%3)==0); is 2?
Does the computer only compute (cout<<14%3), while ignore (2==0)?
Why thc computer don't think ((cout<<14%3)==0) in this process:
check the value of (cout<<14%3), if the value of (cout<<14%3) ia equal to 0, then the result of ((cout<<14%3)==0) is 1 (right), otherwise, is 0 (false)?
Another question:
Why cout<<1%3==0; can output 1, while I can not successfully compile cout<<1%3==0<<endl;?
Last edited by Xiangbuilder; 09-13-2003 at 04:09 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.