Questions tagged [post-increment]

For issues relating to defining or performing post increment operations.

Post-increment operators increase the value of their operand by 1 (or another specified amount), but the value of the operand in the expression is the operand's original value prior to the increment operation.

561 questions
-2
votes
1 answer

How does post-increment work on an assignment(with the same variable)?

I have this code... for(int i=0; i<10 ; ) { i = i++; System.out.println("Hello World"); } Output: Hello World Hello World Hello World... The loop will repeat infinitely, because i remains 0 after every iteration of the loop. I thought…
Luisk4
  • 377
  • 1
  • 5
  • 12
-2
votes
4 answers

Post increment in c

I am getting output as 0..0 in the below given program.Why does j doesn't get incremented while if condition is being checked? int main(int argc, char const *argv[]) { int i=0,j=0; if(i&&j++) printf("%d..%d",i++,j); …
Rahul Gusai
  • 701
  • 1
  • 6
  • 11
-2
votes
1 answer

C++ postfix operator precedence with boolean AND

Up until today I thought I understood C++ operators and precedence. I give you the following simple code: int i = 0, j = 0 i++; j++; cout << i << ' ' << j << endl; Naturally, we expect the output values for i and j to be 1 and 1, respectively. Now…
Max
  • 2,072
  • 5
  • 26
  • 42
-2
votes
3 answers

Priority operators in C

I found this text (source: https://education.cppinstitute.org/) and I'm trying to understand the second instruction. Can you answer the question of what distinguishes these two instructions? c = *p++; and c = (*p)++; We can explain: the first…
Martin
  • 66
  • 5
-2
votes
2 answers

unexpected behaviour of pre and post increment in c language gcc compiler

If n has the value 5 then output: printf("%d %d", n++, ++n); //should be 5 and 7 But I get as output 6 and 7.
-2
votes
2 answers

for loop resulting in infinite loop, when post increment is used

I am new to java. Wanted help to analyse small bit of code as below. Below code prints value of 'i' as 0 always. It seems like 'i' never gets incremented and below for loop results in infinite loop. Can some one explain why 'i' is not getting…
Sathish D
  • 4,854
  • 31
  • 44
-2
votes
3 answers

Js magic need explanation

I'm trying to solve this magic in js: var a = 1; console.log(a++ + ++a); It returns 4 and I can understand that it's 1+3 but what is the sequence of this?
Vadym
  • 548
  • 2
  • 8
  • 21
-2
votes
1 answer

*t++ = *s++ ; String copy

This is a much discussed question however my doubt is that in C, *t++ is equivalent to *(t++) as precedence of ++ (post increment operator) is greater than *. Therefore,in while (*t++ = *s++); won't the first character be skipped while copying from…
sb18
  • 1
  • 1
-2
votes
2 answers

Value of y = x + x++ in Java

Say we have Java code below: int x = 1; int y = x + x++; 'Cause the precedence of "postfix-increment" operator is higher than "add" operator. I think x++ should be calculate and evaluated first. Then it comes to x + (x++). So the y should be…
Qi W.
  • 706
  • 9
  • 21
-2
votes
4 answers

Is post-increment operator guaranteed to run instantly?

Let's say I have the following code: int i = 0; func(i++, i++); The increment is happening right after returning the value? Is it guaranteed that the first argument will be 0, and the second argument will be 1?
iTayb
  • 12,373
  • 24
  • 81
  • 135
-2
votes
3 answers

What is the difference between a++ and a+1?

I was writing a small piece of code wherein I had to increment value of a variable 'j' if the condition matched. for(int i=0;i
Backspace
  • 292
  • 1
  • 4
  • 17
-2
votes
4 answers

Incrementing an array resuit in lvalue required?

Incrementing an array result in lvalue required?my code is below please help me to understand int main() { int a[]={10,20,30,40,50}; a=a+1 ;// i am increment an array address a++ ;// but here its bad, here why lvalue required ? }
-2
votes
2 answers

pre-increment and post- increment

#include int main() { int a = 10; ++a = 20; printf("a = %d", a); getchar(); return 0; } The output obtained for the above code is : a=20; when run as C++ code. #include int main() { int a = 10; …
Trinity
  • 17
  • 3
-2
votes
2 answers

Explain output of C program

#include main() { int i=5; printf("%d %d",i,i++); } Output: 6 5 Can someone please explain this kind of output? Has it something to do with the associativity of the comma operator?
user3126841
  • 155
  • 2
  • 2
  • 9
-2
votes
3 answers

please explain the output the following c program

Could anyone please explain the result of the following C program? #include int main() { int i=2; printf("%d %d %d",i,i++,++i); return 0; } How is the output 4 3 4?