# UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

• Index
• » C
• » Evaluation through precedence

## #1 2009-02-13 08:28 PM

innqubus
Member
Registered: 2007-11-22
Posts: 29

### Re: Evaluation through precedence

#include <stdio.h>
int main()
{
int k =0;
if(k=0 || k++ <6 && ++k <8);
printf("The value of K is %d \n", k);
}

Offline

## #2 2009-02-13 11:18 PM

RobSeace
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

### Re: Evaluation through precedence

if((k=0) || ((k++ <6) && (++k <8)));

Offline

## #3 2009-02-14 03:03 AM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

### Re: Evaluation through precedence

And even if it was legal C, you normally never want to write unclear code like that.
In reality, the code should always be clear and you don't have to know much about
the exact precedence rules at all.

\begin{rant}
That programming courses in general focus more on silly things like this
instead of teaching how to properly write real code might be one of the
reasons we've got so many lousy programmers. I dare not think about how
many great programmers are lost early on because they thought "this is stupid,
let's do something else" while all the lunatics go "I know all the precedence
rules, this stuff is fun!"
\end{rant}

Offline

## #4 2009-02-14 06:00 AM

innqubus
Member
Registered: 2007-11-22
Posts: 29

### Re: Evaluation through precedence

Hello, Thanks for the solution and explanation. Even i strongly despise such "dirty" code as it doesn't finally infer how strong one is in programming skills. But these are the kind of questions we are facing in a "C skills" contest in our company.
I always have a weak link for this Precedence/Associativity evaluation. Even though i have gone through the Chapters in K & R but still i am not able to evaluate properly (Just like the one i asked).
So do u know any trick to solve such questions. I mean a hack to remember it? Even if you know any Web page link that would also do.
Thanks for your quick responses :)

Offline

## #5 2009-02-14 08:53 PM

Nope
From: Germany
Registered: 2004-01-24
Posts: 385
Website

Offline

## #6 2009-02-14 09:03 PM

RobSeace
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Offline

## #7 2009-02-15 07:07 AM

innqubus
Member
Registered: 2007-11-22
Posts: 29

### Re: Evaluation through precedence

Thanks. Shall look into it. :)

Offline

• Index
• » C
• » Evaluation through precedence