problem about precedence-Collection of common programming errors
JetLaggy
php string concatenation operator-keyword precedence
I got some php code here:<?php echo ‘hello ‘ . 1 + 2 . ’34’; ?> which outputs 234,but when I add a number 11 before “hello”:<?php echo ’11hello ‘ . 1 + 2 . ’34’; ?> It outputs 1334 rather than 245(which I expected it to), why is that?
zendao-lee
php reference operator-keyword precedence
I used the reference operator & like this$root=empty($root)?&$this->_item:&$parent;It catch a exception :Multiple annotations found at this line:- syntax error, unexpected ‘:’ – syntax error, unexpected ‘&’But I written like this :if (empty($root)) {$root = &$this->_item;} else {$root = &$parent;}It passed.I want to know why?I read the php manual about operator precedence,& is higher than ?:.
Dave Nolan
ruby arrays syntax precedence splat
Splats are cool. They’re not just for exploding arrays, although that is fun. They can also cast to Array and flatten arrays (See http://github.com/mischa/splat/tree/master for an exhaustive list of what they do.)It looks like one cannot perform additional operations on the splat, but in 1.8.6/1.9 the following code throws “unexpected tSTAR”:foo = bar || *zap #=> unexpected tSTARWhereas this works:foo = *zap || bar #=> works, but of limited valueWhere can the splat appear in an expression
Alexander Marquardt
python order precedence
I have recently been experimenting with python generators a bit, and I came across the following curious behaviour, and I am curious to understand why this happens and what is going on:def generating_test(n): for a in range(n): yield “a squared is %s” % a*a # Notice instead of a**2 we have written a*afor asquare in generating_test(3): print asquare Output:a squared is 1 a squared is 2a squared is 2Versus the following script which generates the expected output:def generating_test(n): for a in ra
ovanes
c# generics methods overloading precedence
experimenting with Visitor pattern and generic method I found a kind of discrepancy in C#.NET. AFAIK C# compiler prefers an explicit overload to a generic method, therefore the following code:public abstract class A {public abstract void Accept(Visitor v); }public class B : A {public override void Accept(Visitor v){ v.Visit(this); } }public class C : A {public override void Accept(Visitor v){ v.Visit(this); } }public class D : A {public override void Accept(Visitor v){ v.Visit(this); } }public c
walther
c# casting operator-keyword precedence
Will the differences below matter significantly in C#?int a, b; double result; result = (double)a / b; result = a / (double)b; result = (double)a / (double)b;Which one do you use?
Mr.Wizard
evaluation variable-definitions precedence
Is there any way to “close” a package (or a symbol, or a context) in that if a user of the package adds definitions to the symbol they will be tried before the package defined ones, just like what happens with built-ins?
assylias
java precedence associativity
int i=9; System.out.println(–i + ++i);output on execution : 17The final value of i is : 9But according to associativity and precedence rules in java,, ++i should be executed first i.e from Right to left which gives 10 and then –i gives 9 .. adding both,, the answer should be 19… As far as i have known such a code gives undefined behaviour in C/C++ but in java ,, the rules are strictly defined and there is no concept of sequence points. So, can anyone clarify the problem as iam really confuse
guest
c error-handling coding-style precedence
is there an advantage in one of the following two approaches over the other?here it is first tested, whether fopen succeeds at all and then all the variable declarations take place, to ensure they are not carried out, since they mustn’t have had tovoid func(void) {FILE *fd;if ((fd = fopen(“blafoo”, “+r”)) == NULL ) {fprintf(stderr, “fopen() failed\n”);exit(EXIT_FAILURE);}int a, b, c;float d, e, f;/* variable declarations *//* remaining code */ }this is just the opposite. all variable declaration
Joachim Pileborg
c arrays printf operator-keyword precedence
Possible Duplicate:Could anyone explain these undefined behaviors (i = i++ + ++i , i = i++, etc…) hello can any one explain the behaviour of below program when i try to solve it printf is supposed to give output 77but output when compiled is 76 why so could any one show the precidence in detail of below statement of printf#include<stdio.h> main() {char s[]={‘a’,’b’,’c’,’\n’,’c’,’\0′};char *p,*str,*str1;p=&s[3];str=p;str1=s;printf(“%d”,++*p+++*str1-32); }Compiler:GCC
Prasanth Bendra
php variables operators operator-precedence precedence
I was trying to answer Why is this code an infinite loop?There I thought the issue could be because of operations precedence, but when I checked http://php.net/manual/en/language.operators.precedence.php , . has more precedence than =so I tried the following code :$a.$b = “test”;echo $a;echo $b;and I got undefined variable a and test which means it is assigning value to $b, How is it assigning value to $b (Should not as per operations precedence)
Web site is in building