Skip to main content

Questions tagged [operators]

Regarding programming languages, operators are constructs which behave generally like functions, but which differ syntactically or semantically from usual functions. From Wikipedia: http://en.wikipedia.org/wiki/Operator_%28programming%29

Filter by
Sorted by
Tagged with
0 votes
1 answer
779 views

I have found another similar question, but the answer there talks mainly about C/C++, and does not mention about the division operator. So, in C/C++ and Java, dividing an integer by an integer returns ...
Arunabh's user avatar
1 vote
3 answers
501 views

Virtually all (imperative) languages offer the operators < <= >= > for lower, lower or equal, greater or equal and greater. But why no ternary range operator like (10 < x < 100) to ...
theking2's user avatar
  • 139
2 votes
3 answers
550 views

I had a debate with a work mate regarding the following code as to which one of it would be the better practice: My code (in pseudo): var A = <precondition either TRUE or FALSE>; var B; if(A) { ...
Chams's user avatar
  • 29
0 votes
1 answer
328 views

I don't know if this is the right place to ask more of a "philosophical" question. The more I code in Java, the more I have to bear with Comparable<T>. And the more I bear with this ...
Thomas Herondale's user avatar
0 votes
4 answers
301 views

I'm currently designing a database query language and I came to wonder what should be the best syntax for the comparison operator. Most modern languages use ==, but amongst the database languages ...
ibi0tux's user avatar
  • 241
18 votes
3 answers
2k views

I'm writing a wrapper for XML elements that allows a developer to easily parse attributes from the XML. The wrapper has no state other than the object being wrapped. I am considering the following ...
John Wu's user avatar
  • 27k
3 votes
1 answer
238 views

For example, say you have a class Point which has floating point components. It's tempting to overload the equality operator so you can do something like a = Point(1.1, 2.2) b = Point(3.3, 6.6) b /= ...
Josie Thompson's user avatar
6 votes
7 answers
4k views

When I was a beginner it took a while to learn the language syntax and the idea that languages couldn't improve after they were invented. But now we're seeing new language features added every year ...
1.21 gigawatts's user avatar
2 votes
1 answer
331 views

I would like to make a simple web application (a static website where all computation happens on the client) that generates a mesh and displays it. I have a working prototype in Unity and now I'm ...
Toast's user avatar
  • 128
1 vote
2 answers
1k views

I recently had a discussion with a friend about code maintainability with regards to modifying an iterator inside of the body of a loop (C# syntax): List<int> test = new List<int>(); for (...
Taco's user avatar
  • 1,175
0 votes
2 answers
1k views

As far as I have been able to find, the first language to use ^ for exponentiation was BASIC, in 1964. Earlier languages, such as Fortran, used other symbols such as ** for exponentiation (although in ...
CoffeeTableEspresso's user avatar
3 votes
1 answer
130 views

For example, to convert between g and kg, I have a constant 1000: public static final float G_TO_KG=1000; . . . this.result = someResult*1000; I found G_TO_KG always bind to operator '*'. So my ...
ocomfd's user avatar
  • 5,760
2 votes
4 answers
4k views

Both the comma operator and the semicolon can be used to separate statements. Let's consider this simple code: #include <stdio.h> void do_something(int*i) {(*i)++;} int main() { int i; ...
gaazkam's user avatar
  • 4,549
58 votes
8 answers
20k views

Is there an operator equivalent of nor? For example, my favorite color is neither green nor blue. And the code would be equivalent to: // example one if (color!="green" && color!="blue") { ...
1.21 gigawatts's user avatar
62 votes
3 answers
12k views

I am a bit confused by the MSDN C# documentation which states that & and | are logical operators and that && and || are conditional operators. I keep calling &&, || and ! logical ...
John V's user avatar
  • 4,946
2 votes
2 answers
565 views

Implementing operator overloading for e.g. + (plus) isn't terribly difficult if you know it's a binary operator. One can just parse expression + expression But what if the programmer can choose ...
Mark's user avatar
  • 682
2 votes
0 answers
431 views

What programming language first used / invented the 'Safe navigation operator' (?.) ? Unfortunately, the Wikipedia page on this subject does not have information on it and googling yielded no readily ...
Daniel's user avatar
  • 136
1 vote
2 answers
3k views

I am wondering what the most idiomatic text abbreviations for comparison operators are. I need to build a custom enum with them, so I cannot use their symbols. To me personally, these seem idiomatic: ...
Felk's user avatar
  • 204
0 votes
4 answers
2k views

Let's say I have a phone that can process 1 million operations per second and a micro controller that can perform 1000. Is there a way to tell how many operations a performed by a function or block ...
1.21 gigawatts's user avatar
3 votes
1 answer
7k views

I'm writing a Matrix type, and I would like the following code to define a 2,2 integer matrix, put its first element at 3, and throw an exception upon reaching the third line: Matrix<int> a(2,2)...
qreon's user avatar
  • 349
3 votes
5 answers
2k views

I understand what increment and decrements operators are (++ and --) and the difference between post and pre (i++ vs ++i) but should they be avoided as they do increase the difficulty of reading the ...
Celeritas's user avatar
  • 605
4 votes
3 answers
218 views

Some operators cannot be overloaded as class members. One such example are the bitwise shift operators used for streams see here for example. The reason for that (as far as I understand it) seems to ...
null's user avatar
  • 3,767
0 votes
2 answers
306 views

I have a code snippet in Java: int y = ++x * 5 / x-- + --x; So my confusion was since x--(postfix) has higher precedence than ++x(prefix) operator so x-- should be executed first then ++x.But a book ...
user1369975's user avatar
  • 1,319
9 votes
6 answers
2k views

In C, * is called the indirection operator or the dereference operator. I understand how it works when it is used in a statement. It makes sense to write *p or * p, considering that it is a unary ...
Torm's user avatar
  • 151
2 votes
2 answers
32k views

Just a basic question on IF statements in programming languages, specifically C++. Consider the following basic code example: int i = 2; if(i == 2 || i == 4) { //do something } Because the first ...
Bob's user avatar
  • 21
0 votes
2 answers
495 views

Recently, I've been learning a bit more of C++ and the dangers and uses of operator overloading, and the readability boost it provides to arithmetic types (like Complex numbers). A while ago, I was ...
Alxe's user avatar
  • 113
1 vote
3 answers
898 views

Which programming languages support operators as first class citizens? eg: Return an operator (+, -, =, ==, etc.) from a function, or store within a variable.
Jordan Mack's user avatar
43 votes
10 answers
9k views

If I want to compare two numbers (or other well-ordered entities), I would do so with x < y. If I want to compare three of them, the high-school algebra student will suggest trying x < y < z....
JesseTG's user avatar
  • 657
44 votes
4 answers
9k views

I mean it in this way: <?php $number1 = 5; // (Type 'Int') $operator1 = +; // (Type non-existent 'Operator') $number2 = 5; // (Type 'Int') $operator2 = *; // (Type non-existent '...
kgongonowdoe's user avatar
-1 votes
1 answer
190 views

What is the difference between these 2 PHP operators ? The first one is = and the second one is .=.
Red Baron's user avatar
61 votes
6 answers
13k views

The plus sign + is used for addition and for string concatenation, but its companion: the minus sign, -, is generally not seen for trimming of strings or some other case other than subtraction. What ...
Digvijay Yadav's user avatar
1 vote
2 answers
2k views

PHP allows you to increment strings. Why? Let's jump ahead a bit. Take the following code: $string = '9ZzZ'; echo ++$string; // 10AaA From a purist point of view this may seem like nonsense, however,...
DanielM's user avatar
  • 253
-1 votes
2 answers
1k views

While the run the below program in Turbo C compiler, I am getting the expected output, however, when I run the same program it using "gcc" compiler in linux, it is giving an unexpected output! int ...
crown679's user avatar
13 votes
1 answer
2k views

The title is be misleading, so please read entire question :-). By "compound assignment operator" I have in mind a construct like this op=, for example +=. Pure assignment operator (=) does ...
greenoldman's user avatar
  • 1,533
3 votes
1 answer
1k views

Some languages have a . operator for string concatenation. The oldest language I could find that supports it is Perl. Was Perl the first to use it? Why was it chosen?
Tyler Holien's user avatar
94 votes
7 answers
18k views

In most languages it is possible to give priority to operators in an if statement based on order. I use this as a way to prevent null reference exceptions, e.g.: if (smartphone != null && ...
innova's user avatar
  • 1,051
14 votes
2 answers
10k views

In C#, we can overload the implicit conversion operator like this (example from MSDN): struct Digit { /* ... */ public static implicit operator byte(Digit d) // implicit digit to byte ...
Mints97's user avatar
  • 799
1 vote
1 answer
2k views

I have seen the -> operator/symbol in Java 8 predicates recently and wondered what its name is. I know that it is used in lambda expressions, but I know that the symbol for lambda is λ, so that's ...
SamTebbs33's user avatar
3 votes
1 answer
855 views

I have written a class to represent bearings (angles with a nautical theme, and a specific normalisation range). In the program, it is necessary to perform some mathematical operations on them, so I'...
wakjah's user avatar
  • 133
0 votes
2 answers
288 views

Below I've produced what I believe to be a summary of the standard $ like operators for various classes in Haskell. There's some gaps however. Following the applicative pattern, you would think those ...
Clinton's user avatar
  • 1,093
4 votes
2 answers
840 views

I’ve come across this blog article: Implicit Conversion Operators are Bad. The article discourages the use of implicit conversion with reference types. The article describes problems caused by ...
Nick Alexeev's user avatar
  • 2,532
3 votes
1 answer
976 views

I'm using a programming language (more a scripting language) that does not support any bitwise operators like AND, OR, XOR, NOT (and shift as well). Common arithmetic and logical operations like + - *...
tigrou's user avatar
  • 279
0 votes
1 answer
264 views

In some languages (C++, Java, Ruby, etc.) an assignment returns a value and can be used in an expression: x = (y = z); // ok, 'x' gets the value of 'z' In other languages (Ada, VHDL), an ...
rick's user avatar
  • 2,005
5 votes
4 answers
2k views

When lexing, what would be the best way to tokenize operators? Would one just create a BinaryOperator token, or a separate token for every single binary operator? Examples: PlusOperator, MinusOperator,...
Jeroen's user avatar
  • 613
14 votes
3 answers
43k views

You can use << to multiply and >> to divide numbers in python when I time them I find using the binary shift way of doing it is 10x faster than dividing or multiplying the regular way. ...
Crizly's user avatar
  • 327
31 votes
3 answers
8k views

Why does the operator -- not exist for bool whereas it does for operator ++? I tried in C++, and I do not know if my question apply to another language. I will be glad to know also. I know, I can ...
aloisdg's user avatar
  • 829
27 votes
9 answers
14k views

I'm developing a language which I intend to replace both Javascript and PHP. (I can't see any problem with this. It's not like either of these languages have a large install base.) One of the things ...
billpg's user avatar
  • 729
0 votes
5 answers
1k views

I'm moving over to work on a library that a fellow developer has been writing. It's full of == true and == false, which I find crazy frustrating to read. I've tried asking him to quit doing it, but ...
RodeoClown's user avatar
3 votes
3 answers
1k views

Why do we need the switch statement if there is the if statement? Why can't we use several ifs like if(a==1) do this1; if(a==2) do this2; ... instead of switch (a) { case(1): {do this1;...
user114292's user avatar
5 votes
2 answers
2k views

Why is there no exponentiation operation in hardware, even though many languages have builtin operators for it? Is it because even hardware implementations would need to use the same algorithm as ...
user1358's user avatar
  • 341