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
29
votes
4 answers

Why do the INC and DEC instructions *not* affect the Carry Flag (CF)?

Why do the x86 instruction INC (increment) and DEC (decrement) not affect the CF (carry flag) in FLAGSREGISTER?
mohammad mahed
  • 511
  • 2
  • 6
  • 11
27
votes
5 answers

Is it safe to put increment/decrement operators inside ternary/conditional operators?

Here's an example #include using namespace std; int main() { int x = 0; cout << (x == 0 ? x++ : x) << endl; //operator in branch cout << "x=" << x << endl; cout << (x == 1 || --x == 0 ? 1 : 2) << endl; //operator in…
jozxyqk
  • 16,424
  • 12
  • 91
  • 180
27
votes
2 answers

Is there an increment operator ++ for Java enum?

Is it possible to implement the ++ operator for an enum? I handle the current state of a state machine with an enum and it would be nice to be able to use the ++ operator.
TomBoo
  • 391
  • 1
  • 4
  • 11
27
votes
15 answers

When does ++ not produce the same results as +1?

The following two C# code snippets produce different results (assuming the variable level is used both before and after the recursive call). Why? public DoStuff(int level) { // ... DoStuff(level++); // ... } , public DoStuff(int level) { //…
Richard Dorman
  • 23,170
  • 16
  • 45
  • 49
26
votes
7 answers

What is the difference between i++ & ++i in a for loop?

I've just started learning Java and now I'm into for loop statements. I don't understand how ++i and i++ works in a for-loop. How do they work in mathematics operations like addition and subtraction?
user228330
  • 277
  • 1
  • 4
  • 3
25
votes
5 answers

Increment with bash

I'm stuck trying to increment a variable in an .xml file. The tag may be in a file 100 times or just twice. I am trying to add a value that will increment the amount several times. I have included some sample code I am working on, but when I run the…
DᴀʀᴛʜVᴀᴅᴇʀ
  • 7,681
  • 17
  • 73
  • 127
23
votes
3 answers

Prefix/Postfix increment operators

I'm wanting to make sure I understand pass-by-value vs pass-by-reference properly. In particular, I'm looking at the prefix/postfix versions of the increment ++ operator for an object. Let's suppose we have the following class X: class X{ private: …
Cam
  • 14,930
  • 16
  • 77
  • 128
23
votes
3 answers

auto increment on composite primary key

I have a table called 'Workspaces' where the columns 'AreaID' and 'SurfaceID' work as a composite primary key. The AreaID references to another table called 'Areas' which only has AreaID as the primary key. What I want to do now is to make the…
xerzina
  • 233
  • 1
  • 2
  • 5
22
votes
7 answers

Avoiding concurrency problems with MAX+1 integer in SQL Server 2008... making own IDENTITY value

I need to increment an integer in a SQL Server 2008 column. Sounds like I should use an IDENTITY column, but I need to increment separate counters for each of my customers. Think of an e-commerce site where each customer gets their own…
stackonfire
  • 1,525
  • 4
  • 17
  • 23
22
votes
3 answers

Pointer Arithmetic: ++*ptr or *ptr++?

I am learning C language and quite confused the differences between ++*ptr and *ptr++. For example: int x = 19; int *ptr = &x; I know ++*ptr and *ptr++ produce different results but I am not sure why is that?
ipkiss
  • 13,311
  • 33
  • 88
  • 123
22
votes
3 answers

Lambda parameter conflicting with class field on accessing field in later scope

I've got a weak imagination when it comes to names, so I often find myself re-using identifiers in my code. This caused me to run into this specific problem. Here's some example code: public delegate void TestDelegate(int test); public class…
user3079266
21
votes
2 answers

Filling an array with numbers sequentially

I have a number (e.g. 6) that is dynamically generated and I would like to fill an array with the numbers 1 through the dynamically generated number (in this example, 6): array(1, 2, 3, 4, 5, 6); The only way I know to do this at the moment is by…
Francis Lewis
  • 8,872
  • 9
  • 55
  • 65
20
votes
3 answers

Auto increment number for multiple lines in PhpStorm

How to achieve auto increment for multiple selection in PhpStorm ie. If I have lines like this selected or taged with multiple cursors my line das my line asd my line sda my line poi my line uio my line kjy And I want to have them automatically…
Eryk Wróbel
  • 416
  • 1
  • 4
  • 11
20
votes
8 answers

What is the difference between pre-increment and post-increment in the cycle (for/while)?

My interest is in the difference between for and while loops. I know that the post-increment value is used and then incremented and the operation returns a constant pre-increment. while (true) { //... i++; int j = i; } Here, will j…
user1886376
19
votes
3 answers

mysql update increment int field that is null

I have a very large table with two INT columns that are null on Default. This is a problem because since they are INT fields, it would help in many cases if they were originally set to 0. So my questions are, is there a way I can UPDATE and…
sa511
  • 205
  • 1
  • 2
  • 4