compound-assignment Questions

3

Solved

We have equivalent assignment operators for all Logical operators, Shift operators, Additive operators and all Multiplicative operators. Why did the logical operators get left out? Is there a good...

17

I need to know what += does in Python. It's that simple. I also would appreciate links to definitions of other shorthand tools in Python.
Vandal asked 30/1, 2011 at 6:0

12

So for binary operators on booleans, Java has &, |, ^, && and ||. Let's summarize what they do briefly here: JLS 15.22.2 Boolean Logical Operators &, ^, and | JLS 15.23 Condition...

8

Solved

Assignment a number to an attribute using the += operator gives me NaN in JavaScript. This code works as expected: > var result = {}; undefined > result['value'] = 10; 10 > result['value...
Gamelan asked 6/2, 2015 at 14:17

2

Solved

public static void main(String[] args) { int A=5; int B=2; A *= B*= A *= B ; System.out.println(A); System.out.println(B); } When I calculated this problem on paper I found A=200 B=20, but...
Spessartite asked 22/8, 2019 at 22:27

4

Solved

One of my programs is exceeding the time limit when I am using fans = fans + s[i], while when I am using fans += s[i] it is being accepted... Why does this happen? To Explain more , fans is a strin...
Month asked 21/7, 2019 at 10:33

7

Solved

What is the explanation for the result from the following operation? k += c += k += c; I was trying to understand the output result from the following code: int k = 10; int c = 30; k += c += k ...
Colporteur asked 13/2, 2019 at 16:14

3

Solved

Recently I came across this question: Assignment operator chain understanding. While answering this question I started doubting my own understanding of the behavior of the addition assignment oper...
Jokjakarta asked 15/6, 2018 at 5:51

8

Solved

I have a long set of comparisons to do in Java, and I'd like to know if one or more of them come out as true. The string of comparisons was long and difficult to read, so I broke it up for readabil...
Vedavedalia asked 21/3, 2010 at 9:6

1

Solved

I was wondering if there was a difference between =+ and += (and other assignment operators too). I tried and both did the same thing. So is there a difference or is there a convention? Do bo...
Mourning asked 12/1, 2017 at 15:6

4

In C and C++ code, in particular that for embedded systems, I regularly stumble upon assignments that take the following shape: A |= B; A &= B; Not sure if relevant, but A and B are register...
Maryannmaryanna asked 16/11, 2016 at 10:47

1

Solved

There is an article Optimization killers in wiki of Bluebird library. In this article there is a phrase: Currently not optimizable: ... Functions that contain a compound let assignment Func...
Algin asked 4/1, 2016 at 16:19

5

Solved

I tried some code to swap two integers in Java without using a 3rd variable, using XOR. Here are the two swap functions I tried: package lang.numeric; public class SwapVarsDemo { public static...
Mann asked 26/2, 2014 at 14:19

1

Solved

Let's just take for example the specific compound assignment operator ^=. This stackoverflow page says modification of the left operand may have not been done after the evaluation of ^=, and thus m...

2

I'm not sure whether statement below is well defined by standard C or not *p1++ += 2; or other similar statement: *E1++ <operator>= E2 From standard C about post-increment: The resul...
Assignee asked 17/10, 2014 at 2:49

7

Solved

I can’t seem to wrap my head around the first part of this code ( += ) in combination with the ternary operator. h.className += h.className ? ' error' : 'error' The way I think this code works is ...

1

Solved

Given the following property declaration: @property NSInteger foo; How do the increment, decrement, and compound assignment operators actually work on self.foo? It was my understanding that sel...

6

Solved

When writing code like this in C++: bool allTrue = true; allTrue = allTrue && check_foo(); allTrue = allTrue && check_bar(); check_bar() will not be evaluated if check_foo() retu...

3

Solved

This is a question I've been mildly irritated about for some time and just never got around to search the answer to. However I thought I might at least ask the question and perhaps someone can exp...
Roseleeroselia asked 20/11, 2013 at 9:19

4

Solved

The allegedly "clever" (but actually inefficient) way of swapping two integer variables, instead of using temporary storage, often involves this line: int a = 10; int b = 42; a ^= b ^= a ^= b; /...

5

Solved

Recently I saw a code using this: boolean val = something(); val |= somethingElse(); Interesting part is |= (binary like) operator made on boolean primitive type. It surprised me that |= exist ...

3

Solved

In a lot of languages a = a + b can be written as a += b In case of numerical operations, a + b is same as b + a, so the single compound operator suffices. Also, a = a - b can be written as a -=b ...

3

Solved

To my shock, it turns out that the following code will compile without even warnings: public void test() { int value = 2000000000; long increment = 1000000000; value += increment; } Whereas t...
Greece asked 30/3, 2011 at 1:21

1

Solved

I'm very convinced with the explanation I've found that said that i = ++i is not undefined as far as C++11 is concerned, but I'm unable to judge whether the behavior of i += ++i is well-defined or ...
Cassimere asked 14/10, 2010 at 10:42

1

Thanks to the implicit casting in compound assignments and increment/decrement operators, the following compiles: byte b = 0; ++b; b++; --b; b--; b += b -= b *= b /= b %= b; b <<= b >>...

© 2022 - 2024 — McMap. All rights reserved.