Questions tagged [decrement]

Subtracting one from the value of a variable, generally with the use of an decrement operator.

Subtracting one from the value of a variable, generally with the use of an decrement operator(--).

425 questions
11
votes
2 answers

Accessing a variable of a thread from another thread in java

I'm trying to access and modify a variable of a thread in another thread in java, and I really don't know how to do this. ex : Runnable r1 = new Runnable() { int value = 10; public void run() { // random stuff } } Runnable r2 =…
Theriotgames Riot
  • 333
  • 3
  • 6
  • 14
10
votes
6 answers

What are the historical reasons C languages have pre-increments and post-increments?

(Note: I am not asking about the definitions of pre-increment vs. post-increment, or how they are used in C/C++. Therefore, I do not think this is a duplicate question.) Developers of C (Dennis Ritchie et al) created increment and decrement…
ShanZhengYang
  • 16,511
  • 49
  • 132
  • 234
9
votes
4 answers

Increment and Decrement operators in scheme programming language

What are the increment and decrement operators in scheme programming language. I am using "Dr.Racket" and it is not accepting -1+ and 1+ as operators. And, I have also tried incf and decf, but no use.
unknownerror
  • 2,235
  • 2
  • 25
  • 26
9
votes
2 answers

Efficient methods for Incrementing and Decrementing in the same Loop

Suppose some situations exist where you would like to increment and decrement values in the same for loop. In this set of situations, there are some cases where you can "cheat" this by taking advantage of the nature of the situation -- for example,…
Anthony Neace
  • 25,013
  • 7
  • 114
  • 129
8
votes
0 answers

++ or -- Incrementer or Decrementer Speed Comparison

Classmate mentioned to me that he read the decrementer (--) was supposed to perform operations faster than the incrementer (++). We ran a test with JavaScript and came up with mixed results. On my MacBook Pro i5 (mid-2014), ++ was almost 3 times…
John Halbert
  • 1,320
  • 2
  • 12
  • 23
7
votes
6 answers

Decrement a For Loop?

I can increment a FOR loop in xcode, but for some reason the reverse, namely decrementing, doesn't work. This incrementing works fine, of course: for (int i=0; i<10; ++i) { NSLog(@"i =%d", i); } But, this decrementing doesn't produce a…
Michael Young
  • 414
  • 1
  • 7
  • 16
7
votes
3 answers

How do I know if my iterator was decremented past the beginning of my vector?

I am moving an iterator backward and forwards through a vector. I can check if the iterator ran off the end like so: ++my_iterator; if ( my_iterator == my_vector.end() ) { --my_iterator; // if I want to stop the iterator at the end. …
user542687
7
votes
1 answer

How to implement a decrementing for loop in Julia?

I know that in python I can do something as follows. for i in range(10, 0, -1): print(i) Which will output: 10 9 8 7 6 5 4 3 2 1 I'm very much new to julia and I know I can create normal loops as follows. for i=1:10 …
Bilesh Ganguly
  • 3,792
  • 3
  • 36
  • 58
7
votes
3 answers

Precedence of increment and decrement opreators in C++

I tried this on my gcc: int a=1; cout<<(--a)--; and the output is 0; but change it to cout<<--(a--); results in an error (lvalue required as decrement operand). Could someone enlighten me about this? Thanks!
zw324
  • 26,764
  • 16
  • 85
  • 118
7
votes
10 answers

In Java, why can't I write i++++ or (i++)++?

When I try to write a postfix/prefix in/decrement, followed by a post/prefix in/decrement, I get the following error: Invalid argument to operation ++/--. But, according to JLS: PostIncrementExpression: PostfixExpression…
John Assymptoth
  • 8,227
  • 12
  • 49
  • 68
7
votes
2 answers

Why does C++ accept multiple prefixes but not postfixes for a variable

While looking into Can you have a incrementor and a decrementor on the same variable in the same statement in c I discovered that you can have several prefix increment/decrement operators on a single variable, but only one postfix ex: ++--++foo; //…
Ashterothi
  • 3,282
  • 1
  • 21
  • 35
6
votes
2 answers

Thread unsafe decrementing/incrementing - why mostly positive?

I'm wondering about result of unsafe decrementing/incrementing in java threads, so there is my program: Main class: public class Start { public static void main(String[] args) { int count = 10000000, pos = 0, neg = 0, zero = 0; …
Nazin
  • 827
  • 3
  • 16
  • 31
6
votes
2 answers

Java expression interpretation rules of decrement/increment operators

This is a purely theoretical question, I wouldn't write this code normally, for clarity's sake. Why is this quite ambiguous statement legal int a = 1, b = 2; int c = a---b; // a=0, b=2, c=-1 (it is interpreted as a-- -b) and this one isn't? int c…
radoh
  • 4,554
  • 5
  • 30
  • 45
6
votes
4 answers

How does the decrement operator work in a while statement?

I have the following code source in C: #include void main() { int i=0, x=3; while((x---1)) { i++; } printf("%d", i); } How does this while statement work and why does it print 2 instead of 1?
Dog
  • 474
  • 8
  • 25
5
votes
2 answers

Recursive function for finding factorial of a number

I am getting an output of 24 which is the factorial for 4, but I should be getting the output for 5 factorial which is 120 #include int factorial(int number){ if(number==1){ return number; } return…
ash54321
  • 133
  • 1
  • 9
1
2
3
28 29