Questions tagged [operators]

Operators are symbols that occur in nearly all programming and coding languages, for performing calculations and comparisons on data.

There are three main types of operators:

  • Arithmetic operators such as add (+), subtract (-), times (*), divide (/) and other numerical calculations.

  • Comparison operators, which give the result of a comparison between numbers or strings, for example greater than (>), less than (<), equal to (==).

  • Logical operators include things like AND (&&) and OR (||).

There are other operators, such as assignment and concatenation.

Use this tag for any questions relating to operators, in any language, including things such as syntax, behaviour and use.

7554 questions
9843
votes
29 answers

What is the "-->" operator in C++?

After reading Hidden Features and Dark Corners of C++/STL on comp.lang.c++.moderated, I was completely surprised that the following snippet compiled and worked in both Visual Studio 2008 and G++ 4.4. Here's the code: #include int main() { …
GManNickG
  • 483,438
  • 51
  • 484
  • 539
7477
votes
30 answers

Does Python have a ternary conditional operator?

Is there a ternary conditional operator in Python?
Devoted
  • 170,803
  • 42
  • 89
  • 110
5652
votes
48 answers

Which equals operator (== vs ===) should be used in JavaScript comparisons?

I'm using JSLint to go through JavaScript, and it's returning many suggestions to replace == (two equals signs) with === (three equals signs) when doing things like comparing idSele_UNVEHtype.value.length == 0 inside of an if statement. Is there a…
bcasp
  • 57,407
  • 4
  • 18
  • 14
4961
votes
23 answers

Reference — What does this symbol mean in PHP?

What is this? This is a collection of questions that come up every now and then about syntax in PHP. This is also a Community Wiki, so everyone is invited to participate in maintaining this list. Why is this? It used to be hard to find questions…
Gordon
  • 307,398
  • 72
  • 526
  • 551
3935
votes
41 answers

What is the !! (not not) operator in JavaScript?

I saw some code that seems to use an operator I don't recognize, in the form of two exclamation points, like so: !!. Can someone please tell me what this operator does? The context in which I saw this was, this.vertical = vertical !== undefined ?…
Hexagon Theory
  • 41,929
  • 5
  • 25
  • 30
3799
votes
11 answers

Why don't Java's +=, -=, *=, /= compound assignment operators require casting?

Until today, I thought that for example: i += j; Was just a shortcut for: i = i + j; But if we try this: int i = 5; long j = 8; Then i = i + j; will not compile but i += j; will compile fine. Does it mean that in fact i += j; is a shortcut for…
2384
votes
8 answers

What are the basic rules and idioms for operator overloading?

Note: The answers were given in a specific order, but since many users sort answers according to votes, rather than the time they were given, here's an index of the answers in the order in which they make the most sense: The General Syntax of…
sbi
  • 214,397
  • 45
  • 250
  • 435
2292
votes
4 answers

What does the ??!??! operator do in C?

I saw a line of C that looked like this: !ErrorHasOccured() ??!??! HandleError(); It compiled correctly and seems to run ok. It seems like it's checking if an error has occurred, and if it has, it handles it. But I'm not really sure what it's…
Peter Olson
  • 133,276
  • 48
  • 198
  • 239
1531
votes
17 answers

Is there a "null coalescing" operator in JavaScript?

Is there a null coalescing operator in Javascript? For example, in C#, I can do this: String someString = null; var whatIWant = someString ?? "Cookies!"; The best approximation I can figure out for Javascript is using the conditional operator: var…
1497
votes
10 answers

What are bitwise shift (bit-shift) operators and how do they work?

I've been attempting to learn C in my spare time, and other languages (C#, Java, etc.) have the same concept (and often the same operators)... At a core level, what does bit-shifting (<<, >>, >>>) do, what problems can it help solve, and what…
1000
votes
11 answers

Behaviour of increment and decrement operators in Python

How do I use pre-increment/decrement operators (++, --), just like in C++? Why does ++count run, but not change the value of the variable?
Ashwin Nanjappa
  • 73,610
  • 79
  • 207
  • 291
906
votes
4 answers

JavaScript plus sign in front of function expression

I’ve been looking for information about immediately invoked functions, and somewhere I stumbled on this notation: +function(){console.log("Something.")}() Can someone explain to me what the + sign in front of the function means/does?
jOpacic
  • 9,393
  • 12
  • 35
  • 58
622
votes
11 answers

What is the use of the @ symbol in PHP?

I have seen uses of @ in front of certain functions, like the following: $fileHandle = @fopen($fileName, $writeAttributes); What is the use of this symbol?
sv_in
  • 13,759
  • 9
  • 33
  • 55
600
votes
11 answers

"is" operator behaves unexpectedly with integers

Why does the following behave unexpectedly in Python? >>> a = 256 >>> b = 256 >>> a is b True # This is an expected result >>> a = 257 >>> b = 257 >>> a is b False # What happened here? Why is this False? >>> 257 is 257 True …
Greg Hewgill
  • 908,125
  • 177
  • 1,131
  • 1,267
586
votes
8 answers

What's the difference between equal?, eql?, ===, and ==?

I am trying to understand the difference between these four methods. I know by default that == calls the method equal? which returns true when both operands refer to exactly the same object. === by default also calls == which calls equal?... okay,…
denniss
  • 16,659
  • 26
  • 90
  • 138
1
2 3
99 100