Questions tagged [operators]
Operators are symbols that occur in nearly all programming and coding languages, used for performing calculations, comparisons, and assignments of data. Use this tag for any questions relating to operators, in any language, including things such as syntax, behaviour and use.
operators
7,830
questions
10169
votes
26
answers
1.0m
views
What is the '-->' operator in C/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. ...
7956
votes
31
answers
2.9m
views
Does Python have a ternary conditional operator?
Is there a ternary conditional operator in Python?
5645
votes
47
answers
2.2m
views
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....
5109
votes
25
answers
838k
views
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
What is this?
This is a collection of questions that come up now and then about syntax in PHP. This is also a Community Wiki, so everyone is invited to participate in maintaining this list.
This ...
4170
votes
36
answers
946k
views
What is the !! (not not) operator in JavaScript?
I saw this code:
this.vertical = vertical !== undefined ? !!vertical : this.vertical;
It seems to be using !! as an operator, which I don't recognize. What does it do?
3856
votes
11
answers
318k
views
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.
...
2550
votes
4
answers
395k
views
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 ...
2470
votes
10
answers
1.0m
views
What are the basic rules and idioms for operator overloading?
Note: This question and the original answers are from 2010 and partially outdated. Most of it is still good and helpful, but the original text no longer covers everything there is to know about C++ ...
1809
votes
5
answers
203k
views
What is ':-!!' in C?
I bumped into this strange macro code in /usr/include/linux/kernel.h:
/* Force a compilation error if condition is true, but also produce a
result (of value 0 and type size_t), so the expression ...
1567
votes
19
answers
473k
views
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 ...
1553
votes
11
answers
894k
views
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 (<<, >&...
1065
votes
11
answers
1.5m
views
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?
914
votes
4
answers
95k
views
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 ...
639
votes
11
answers
266k
views
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?
616
votes
11
answers
109k
views
"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 = ...