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
-1
votes
1 answer

Pre increment and post increment function call

#include int main() { void add(); int i=2; add(i++,--i); print("%d",i) } void add(int a,int b) { print("%d %d",a,b); } /*what are a and b's value i am actually not getting the answer why b is 2 */
-1
votes
1 answer

Why lvalue required as increment operand?

I know those precedence and associativity at all, but I cant able to sort the error correctly for this expression. c=b|i+++++j;
-1
votes
6 answers

How increment operators work in do while loop?

#include int main(){ int i = 0; do { i++; printf("In while loop\n"); } while (i < 3); } output: In while loop In while loop In while loop Why the printf statement is executed three times? As soon as the loop…
Pankaj Mahato
  • 1,051
  • 5
  • 14
  • 26
-1
votes
1 answer

value of variable after many post or pre increments

I am almost new to programming. I see a lot of questions of this type in many question papers and exams int j= 5; int i=0; i= j++ + ++j + j++ - ++j ; I always predict the wrong value of variable 'i'. My friends suggested many approaches but all…
newbie
  • 29
  • 4
-1
votes
2 answers

Output of the program((confused))

Can you explain the output of the following program: #include using namespace std; int main() { int a=10; int x=(a++)+(++a)+(a++)+(a++)+(++a); cout<
-1
votes
1 answer

Different between x++ and ++x

I've known that primary operator (x++) is different form unary operator (++x) when combine with another operator in a statement. But I wonder whether those two operator is same when leave them alone on the statement. I mean about compiled code,…
Tu Tran
  • 1,957
  • 1
  • 27
  • 50
-1
votes
2 answers

pre-increment and post-increment in printf

int main() { int value = 4321; int *ptrVal = &value; printf("%d %d",++value,(*(int*)ptrVal)--); return 0; } How does pre-increment/post increment works in above print statement ? And why is answer 4321 4321 ?
Rohit
  • 6,941
  • 17
  • 58
  • 102
-1
votes
2 answers

Behaviour of C# code

Possible Duplicate: Explaining post-increment in C# Consider the following C# code:- int i = 2; i = i++; Console.WriteLine(i); I am getting the output as 2. Why there is no effect of i = i++?
Jainendra
  • 24,713
  • 30
  • 122
  • 169
-2
votes
0 answers

Variable assigned it's post-incremented value

My question is regarding assigning a variable to it's post-incremented value. This was undefined in previous versions of C as pointed out in this question but it's defined in C17. I've followed this StackOverflow post regarding post-incrementing…
nobis
  • 1
  • 2
-2
votes
2 answers

Whats the order of operations with respect to 'return' in C

I was shocked by the output of this... been coding in C for a few years now. Could someone explain a possible use case? Seems like it should be a compiler warning. #include int chk(int var) { return var++; } int main (void) { int…
Greasyjoe
  • 95
  • 1
  • 7
-2
votes
2 answers

*a++ = *b++ (what does it mean, how it works)

What would be the values after performing this operation? #include int main() { int *a = 0; int *b = 3; *a++ = *b++; printf("%d", a); printf("%d", b); return 0; } The code above gives me a segmentation fault.
-2
votes
1 answer

What will this display?

This code was in a quiz of Dart course that I'm taking, please help me solve it. I want to know what it should display. I solved it as 6, but the answer was 1, but I don't know why. int var1 = 5; int var2 = 6; if ((var2 = 1) == var1) …
-2
votes
2 answers

why doesn't the result of an array member changed when have assigned it?

when I did something like this: int arr[]={11, 12, 13, 14, 15}; int *p=arr; *(p++) += 100; The result of arr[1] was still 12,why?
-2
votes
2 answers

Please Explain what is difference between i=i++; and i++. Please look at code below and make me understand how it works in case of first condition?

look at these two conditions in the code and output respectively: #include using namespace std; int main() { int i=1; i=i++; // first condition i++; //2nd condition cout << i << endl; //it will print 2 in second…
-2
votes
2 answers

Increment inside the for loop and outside the for loop

in the following loop which i++ will be executed first?the one which is inside the for loop or the one at line no 3? enter code here 1.for(i = 0; i < 3; i++) { 2.a[i] = a[i] + 1; 3.i++; 4.}