LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-25-2008, 09:27 AM   #16
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled

The orders of precedence of , and && are completely different. Comma is appropriate in some cases:
Code:
#include <stdio.h>

int main()
{
	int one, two;

	one = 1, two = 0;

	fprintf(stderr, ", : %i %i\n", one, two);

	one = 1 && (two = 0);

	fprintf(stderr, "&&: %i %i\n", one, two);

	return 0;
}
ta0kira

Last edited by ta0kira; 04-25-2008 at 10:10 AM.
 
Old 04-25-2008, 09:57 AM   #17
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
The operands of , are all evaluated, also, even if one or more are false:
Code:
#include <stdio.h>

int main()
{
	int I, J, K;

	I = J = 1;
	K = (I = 0) && (J = 0);

	fprintf(stderr, "1: %i %i %i\n", I, J, K);

	I = J = 1;
	K = (I = 0, J = 0);

	fprintf(stderr, "2: %i %i %i\n", I, J, K);

	I = J = 1;
	for (I = 0, J = 0; I || J; J = 0, I = 0)
	fprintf(stderr, "3: %i %i\n", I, J);

	I = J = 1;
	for ((I = 0) && (J = 0); I || J; (J = 0) && (I = 0))
	fprintf(stderr, "4: %i %i\n", I, J);

	fprintf(stderr, "5: %i %i\n", I, J);

	return 0;
}
ta0kira

Last edited by ta0kira; 04-25-2008 at 10:14 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need a script to remove last comma in a file jgombos Programming 15 01-14-2008 01:30 PM
Comma key doesn't work mengkai Linux - Laptop and Netbook 1 03-05-2004 11:42 PM
Swedish keyboard + GNOME = no comma ziggamon Linux - Software 0 11-28-2003 02:38 PM
Comma-Delimited Website Filenames Apocalypse General 1 11-09-2003 09:05 AM
comma delimited file cdragon Programming 5 06-21-2002 07:55 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration