Questions tagged [increment]

DO NOT USE THIS TAG ALONE. Use with a language tag like [javascript] or [python]. Adding one to the value of a variable, generally with the use of an increment operator.

Adding one to the value of a variable, generally with the use of an increment operator.

3520 questions
16
votes
6 answers

Incrementing Pointers

I have a question about incrementing in pointers that I dont quite understand. Lets see 2 small programs: int iTuna=1; int* pPointer= &iTuna; *pPointer = *pPointer + 1 ; //Increment what pPointer is pointing to. cout << iTuna << endl; In this first…
Mohamed Ahmed Nabil
  • 3,949
  • 8
  • 36
  • 49
15
votes
1 answer

Incrementing a variable triggers EXIT in bash 4, but not in bash 3

Consider this (exemplary) bash script: #!/bin/bash -e errorExit() { echo "" >&2 echo "ERROR (${var_scriptfilename}):" >&2 echo "An unhandled error occurred." >&2 intentionalExit 1 } intentionalExit () { trap - EXIT # Unregister…
eomanis
  • 153
  • 7
15
votes
3 answers

Using if else in For Loop increment

I have a problem in Java: Given a string, return a string made of the chars at indexes 0,1,4,5,8,9... I know how to solve it, however I was wondering if it's possible for me to use if-else in for-loop increment itself, for example: for (int i=0;…
micahyoung
  • 171
  • 1
  • 11
15
votes
1 answer

Updating project version number on git push

I have a project hosted on Github, and I would like to set it up such that the project has a version number, and the version number is only updated when the master branch is updated, either directly by a push, or via a merged Pull Request. Is there…
dabs
  • 727
  • 1
  • 7
  • 23
15
votes
3 answers

Sublime Text 2 increment numbers

I have a JSON file that looks like this: "Algeriet" : [ { "name" : "Nyårsdagen", "date" : "2013-01-01", "ID" : "1" }, { "name" : "Mawlid En Nabaoui Echarif", …
Peter Warbo
  • 11,136
  • 14
  • 98
  • 193
14
votes
4 answers

++i operator difference in C# and C++

I have the following code written in both C++ and C# int i=0; ++i = 11; After this C# compiler brings an error The left-hand side of an assignment must be a variable, property or indexer But C++ compiler generate this code with no error and I…
shift66
  • 11,760
  • 13
  • 50
  • 83
14
votes
3 answers

bash set -e and i=0;let i++ do not agree

the following script with debug option 'set -e -v' fails at the increment operator only when the variable has a prior value of zero. #!/bin/bash set -e -v i=1; let i++; echo "I am still here" i=0; let i++; echo "I am still here" i=0; ((i++)); echo…
bliako
  • 977
  • 1
  • 5
  • 16
14
votes
3 answers

MongoDB field increment with max condition in update statement

For MongoDB I'm looking for atomic update that will increment field and if that increment will exceeds maximum given number it will stat that maximum number. Same behavior can be achieved with combination of $inc and $min operators but sadly not in…
michal.kreuzman
  • 12,170
  • 10
  • 58
  • 70
14
votes
2 answers

+= with multiple variables in python

I'm trying to increment multiple variables at the same time and stick it into one line. What would be the most pythonic way to do this if there is a way?
user3255511
  • 151
  • 1
  • 1
  • 3
14
votes
2 answers

incrementing struct members

Say I have a struct defined as follows struct my_struct { int num; }; .... Here I have a pointer to my_struct and I want to do an increment on num void foo(struct my_struct* my_ptr) { // increment num // method #1 …
user1508893
  • 9,223
  • 14
  • 45
  • 57
13
votes
5 answers

Incrementing: x++ vs x += 1

I've read that many developers use x += 1 instead of x++ for clarity. I understand that x++ can be ambiguous for new developers and that x += 1 is always more clear, but is there any difference in efficiency between the two? Example using for…
beatgammit
  • 19,817
  • 19
  • 86
  • 129
13
votes
3 answers

Different results when using increment operator (arr[i++] vs arr[i]; i++;)

I can't get my head around why the code below is not working as expected: #include int main() { int i = 0, size = 9, oneOrZero[] = {1,1,1,1,1,1,1,1,0}; while (i < size && oneOrZero[i++]); if (i == size) printf("All ones");…
milancodes
  • 173
  • 1
  • 7
13
votes
2 answers

Why does Knuth use this clunky decrement?

I'm looking at some of Prof. Don Knuth's code, written in CWEB that is converted to C. A specific example is dlx1.w, available from Knuth's website At one stage, the .len value of a struct nd[cc] is decremented, and it is done in a clunky way: …
Ed Wynn
  • 295
  • 1
  • 8
13
votes
1 answer

is the expiration time updated in memcached after an increment?

When you put a value in memcached, you can set an expiration time. However, when you increment a value you can not (at least not from PHP) set a new expiration time. My question: Is the expiration time reset on increment to it's initial value? Or it…
Toad
  • 15,593
  • 16
  • 82
  • 128
13
votes
2 answers

Java return statement with increment - what is the general behavior?

I just learned that if a return statement contains an increment operation, the return will execute first and the value will be returned before it is incremented. If I increment first in a separate statement, and then return, it works as expected.…
DrH
  • 131
  • 1
  • 1
  • 3