Questions tagged [pre-increment]

For issues relating to defining or performing pre increment operations.

Pre-increment operators increase the value of their operand by 1 (or another specified amount), and the value of the operand in the expression is the operand's value after the increment operation.

342 questions
0
votes
1 answer

How is alert(++[[]][+[]]+[+[]]); calculated to 0?

How is alert(++[[]][+[]]+[+[]]); calculated to 0? What is this process called so that I can read more about this
Deepika Rao
  • 145
  • 1
  • 3
  • 11
0
votes
4 answers

How does this code produces an output of 6 and 3?

#include void main() { int x = 0,y = 0,k = 0; for(k = 0; k < 5; k++){ if(++x > 2 && ++y > 2) x++; } printf("x = %d and y = %d",x,y); } I'm not able to understand how the above piece of code generates x = 6…
shri cool
  • 95
  • 2
  • 11
0
votes
0 answers

Interaction between #define and incremet/decrement operators

I'm trying to figure out what is the issue with the following code. I have the idea, based on various internet search, that it causes undefined behavior but i'd like to have better understanding. #include #define SQUARE (x) x*x int…
0
votes
1 answer

Overloaded preincrement operator using result of variable inside overloaded postincrement operator

I have an overloaded preincrement operator that is supposed to take a complex number like (3+6i)....which is, in this case, a, and run it through a square function that turns it into (-27+36i). I also have a postincrement operator that does the same…
0
votes
1 answer

Overloaded preincrement operator error "more than one operator ++ matches these operands"

I have overloaded postincrement (a++) operator in my code and I am attempting to overload the preincrement operator (++a) in my code to perform a function that squares the complex number "a", however, only the postincrement operator is working at…
garyoak
  • 41
  • 3
0
votes
1 answer

Macro and Pre/Post Increment in C

I have noticed this strange behavior of macro functions while using pre increment operator. I know it is not preferable to use pre increment operator with macros but still I would like to know the reason behind the execution of the following 2…
0
votes
0 answers

Execution of multiple increment operators

How would the output of int i = 6; i += ++i + ++i + i++ + --i; printf("%d", i); be evaluated. When I do it on paper I get 39. But the output after executing is 40.
deezpeeps
  • 114
  • 2
  • 10
0
votes
3 answers

C++ Incrementing a Pointer

Why can I do something like *x = *x+1;, but doing something like *x = *x++; doesn't seem to have any affect? Code: // Example program #include #include using namespace std; void doSomething(int *x, int *y) { *x = *x++; …
simon
  • 854
  • 1
  • 9
  • 23
0
votes
1 answer

Pointer to pointer dereference with pre-increment operator

The following program gives output as 17,29,45; I can't understand what does **++pp; mean. Can anyone explain the program in detail. #include int main() { static int a[] = {10, 22, 17, 29, 45}; static int *p[] =…
Nikhil Verma
  • 1,777
  • 1
  • 20
  • 41
0
votes
0 answers

pre-increment additions confusion

Hello Stackoverflowers, Considering the following pre-increment addition, can you explain me why j = 8 in the following code ? int i = 2; int j = ++i + ++i; //j = 8, why ??
Csi
  • 526
  • 3
  • 22
0
votes
3 answers

for Repetition Statement in c

When for statement is executed the value of counter variable has to be increased by one because I use pre-increment operator. #include int main (void) { unsigned int counter ; for ( counter = 1; counter <= 10; ++counter /*here is…
0
votes
1 answer

Post/Pre-Increment confusion

From what I understand, if I have a variable k = 5, and I do ++k, the new value of k = 6. If I do k++, the value remains 5 until k appears the second time in the program, which is when it is changed to 6. For e.g: k = 5; System.out.println(k++);…
User2956
  • 11
  • 3
0
votes
0 answers

Pre-increment of variable in gcc compiler

The output is coming out to be 150. How? include using namespace std; int main() { int j, i=3; j=(++i)*(++i)*(++i); cout<
Nikita Gupta
  • 9
  • 1
  • 3
0
votes
1 answer

getting weird answer about pre-increment value

i got final tomorrow & stuck in this question . Let's say ( c++ ) x = 1; cout << ++x + ++x; // this gives me equals to 6 ! isn't it suppose to be 5 ? ( 2 + 3 ) i'm lost , any help would be truly appreciated .
Kok Sin
  • 1
  • 1
0
votes
1 answer

Javascript $('li').length call throws uncaught exception

I've built a little webpage with a carousel image slider. The slider has buttons which when clicked upon trigger an image change and also some corresponding text to appear below the slider. Right now the slider has four images. When I click the…