operators

How does the '&' symbol in PHP affect the outcome?

I've written and played around with alot of PHP function and variables where the original author has written the original code and I've had to continue on developing the product ie. Joomla Components/Modules/Plugins and I've always come up with this question: How does the '&' symbol attached to a function or a variable affect the outcom...

What is the difference between '==' and '=' ?

I know that one of them is bitwise and the other is logical but I can not figure this out: Scanner sc = new Scanner(System.in); System.out.println("Enter ur integer"); int x=sc.nextInt(); if(x=0)//Error...it can not be converted from int to boolean System.out.println("..."); The error means that x cannot be converted to boolean or the...

what does this C++ macro do ?

This is for MSVC #define Get64B(hi, lo) ((((__int64)(hi)) << 32) | (unsigned int)(lo)) Specifically, what is the role of the 'operator <<' ? Thanks for your help ...

In csh, why does 4 - 3 + 1 == 0?

#!/bin/csh @ cows = 4 - 3 + 1 echo $cows This simple csh script when run produces "0" for output when I'd expect "2". ~root: csh simple.1 0 I did a bunch of looking and the only thing I could think of was that the "-" was being read as a unary negation rather than subtraction, therefore changing operator precedence and ending up wi...

Why are operators right associative in CShell that are left associative in C?

Following up from my previous question, why is CShell so different from C? 4 - 3 + 1 = 2 in C. 4 - 3 + 1 = 0 in CShell. Any ideas? ...

Which is preferred: foo(void) or foo() in C++

I have seen two styles of defining conversion operator overload in C++, operator int* (void) const operator int*() const Question 1. I think the two styles (whether add void or not) have the same function, correct? Question 2. Any preference which is better? ...

What is the use of @ symbol in php?

I have seen using @ in front of certain functions like following: $fileHandle = @fopen($fileName, $writeAttributes); What is the use of this symbol? ...

Java's >> versus >>> Operator?

I'm without my Java reference book and I'm having a tough time finding an answer with Google. What is the difference between the ">>" and ">>>" operators in Java? int value = 0x0100; int result = (value >> 8); System.out.println("(value >> 8) = " + result); // Prints: "(value >> 8) = 1" result = (value >>> 8); System.out.println("(v...

Is it possible to create a new operator in c#?

I know you can overload an existing operator. I want to know if it is possible to create a new operator. Here's my scenario. I want this: var x = (y < z) ? y : z; To be equivalent to this: var x = y <? z; In other words, I would like to create my own <? operator. ...

Reference-type conversion operators: asking for trouble?

When I compile the following code using g++ class A {}; void foo(A&) {} int main() { foo(A()); return 0; } I get the following error messages: > g++ test.cpp -o test test.cpp: In function ‘int main()’: test.cpp:10: error: invalid initialization of non-const reference of type ‘A&’ from a temporary of type ‘A’ test.cpp:6: er...

jQuery - Change image based on click

Currently I have a heading with a downwards pointing icon. If the header is clicked, I want the image to change to an upwards one. I have tried using the "?" operator to query if it is, but I am not 100% sure how it works. I'm using this code at the moment. // Toggle message_body $(".message_head").click(function(){ var id = $(this).a...

Automatically catching the use of =+ rather than += in Java

I have this horrible habit of typing the below and not catching it until well into testing: int i = 1; int j = 2; i =+ j; //i equals 2, not 3 as intended; assign only, + is unary and works on the j The correct version, of course, would be int i = 1; int j = 2; i += j; //i equals 3, as intended with additive & assignment compound o...

Printing python modulus operator as it is over command line

I want to print modulus operator as it is over the command line: E.g this is how the output should look like: 1%2 2%4 or 30% 40% I am using the print statement like this: print 'computing %s % %s' % (num1, num2) Its throwing the default error: TypeError: not all arguments converted during string formatting For now I am ...

Using the AND and NOT Operator in Python

Here is my custom class that I have that represents a triangle. I'm trying to write code that checks to see if self.a, self.b, and self.c are greater than 0, which would mean that I have Angle, Angle, Angle. Below you will see the code that checks for A and B, however when I use just self.a != 0 then it works fine. I believe I'm not...

Python operators

I am learning Python for the past few days and I have written this piece of code to evaluate a postfix expression. postfix_expression = "34*34*+" stack = [] for char in postfix_expression : try : char = int(char); stack.append(char); except ValueError: if char == '+' : stack.append(stack.pop() + stack.pop(...

Overloading += in c++

If I've overloaded operator+ and operator= do I still need to overload operator+= for something like this to work: -?- MyClass mc1, mc2; mc1 += mc2; ...

Is there a difference between x++ and ++x in java?

Is there a difference between ++x and x++ in java? ...

does python have conversion operators?

I don't think so, but I thought I'd ask just in case. For example, for use in a class that encapsulates an int: i = IntContainer(3) i + 5 And I'm not just interested in this int example, I was looking for something clean and general, not overriding every int and string method. Thanks, sunqiang. That's just what I wanted. I didn't ...

What does "===" mean?

I recently studied some code that I'm supposed to use for different reasons, it's unrelevant. The thing I've noticed is someone using the operator "===" which I can't make sense out of. I've tried it with a function and it corresponds in crazy ways. The language is PHP by the way. Does anyone know what the definition of this operator i...

How do I overload the << operator?

I intend to call a function whenever m_logger<<"hello"<<"world" is called. m_logger is of type ofstream. So i decide to overload << with following signature friend ofstream& operator<<(ofstream &stream,char *str); However the vc compiler gives following error: error C2666: 'operator <<' : 6 overloads have similar conversions Is...