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

post increment,pre increment and operator precedence

the answer is coming out to be 45.I cant understand how this thing is working. main() { int a =10; int i = a++ + ++a + a++ + ++a; printf("%d , %d ", i,a); }
-3
votes
1 answer

How is the postfix and prefix increment operator evaluated in an expression?

#include "stdafx.h" #include #include using namespace std; int main() { int n = 5; cout<< n++ <<" "<< ++n << " "<< n++; _getch(); return 0; } When I run this program on Visual Studio the output is 7 8 5. I think it is…
user2672697
  • 11
  • 1
  • 1
  • 3
-3
votes
1 answer

Evaluation order of increment operations in c

I executed following following code. int main(void) { int c; c=0; printf("%d..%d..%d \n", c,c,c); c=0; printf("%d..%d..%d \n", c,c,c++); c=0; printf("%d..%d..%d \n", c,c++,c); c=0; printf("%d..%d..%d \n",…
Shihab
  • 531
  • 1
  • 12
  • 25
-4
votes
1 answer

I am getting the wrong output when trying post-increment operation on a pointer in C

I am testing out pre- and post-increment on an array using pointer. I use the pointers p and q to access the elements of the array but the issue stems from the last result on pointer p. #include int main(void) { int a[] = {10, 11,…
Monarch
  • 1
  • 1
-4
votes
1 answer

int x = ++n + n++; returns an unexpected value

According to the concept of pre-increment and post-increment operator the output of the following code should be (8+8) = 16, but in the compiler it is evaluated to 17. Please explain with steps. #include using namespace std; int…
-4
votes
1 answer

How to calculate values for -- / ++

I am trying to get the value for the last equation int a = 0, b = 0, c = 0, x = 0, y = 0, z = 0; a = b++ + ++c; printf("a=%d\n", a); x = y + 1 + ++z; printf("x=%d\t", x); printf("b=%d\t", --b); printf("b=%d\t", b++); printf("c=%d\t",…
-4
votes
2 answers

what is the difference between ++*var++ and ++Var++?

What is difference between ++*var++ and ++var++ ? why ++*var++ is working while ++var++ results with lvalue required error in C?
-4
votes
1 answer

pre/post increment decrements evaluation in single line

can you please explain me this. I have read almost all questions on stackoverflow undefined behaviour pre/post inc.. dec.. operator precedence/associativity use the parenthesis but results are inconclusive. please explain this i have an…
-4
votes
1 answer

How are the pre and post increment / decrement operators are evaluated in C++ when they happen to occur repeatedly in a single cout statement?

What is execution strategy that the C++ runtime adopts to produce the output 4545 when executing the below given code. #include using namespace std; int main() { int a=5; cout <
-4
votes
4 answers

Why does ++ not increment correctly?

I wrote a simple function to count the number of non-hidden files in a directory. However I noticed that when I used ++ to increment the count value I got weird results, like negative numbers and really large numbers. When I switch the line…
2trill2spill
  • 1,333
  • 2
  • 20
  • 41
-4
votes
1 answer

problems relating putchar() and recur()

There are some questions from my book which I am unable to understand, I hope you can help me explaining these. Consider following program fragment char c='a' while(c++<='z' putchar(xxx); If required output is abcd.....xyz,then xxx should be (a)…
-4
votes
1 answer

variable length argument in c program

In the following program #include int main() { int a; a=5; printf("%d %d %d\n", a, a++ , a++); //statement 1 a=5; printf("%d %d %d\n", a, ++a , ++a); //statement 2 return 0; } Output 7 6 5 7 7 7 My question why there is different…
night_hawk
  • 101
  • 1
  • 6
-4
votes
3 answers

According to c standard j=i++ * i++ is undefined but j=i++ & i++ is legal why?

According to standard c why it j= i++ * i++ undefined and j=i++ & i++ perfectly legal statement?
Deepak Uniyal
  • 89
  • 3
  • 16
-5
votes
1 answer

Why does the value of i not increment for i=i++; statement?

Code: for(int i=0;i<5;){ i=i++; printf("%d",i); } The above program print zeros infinitely, How is that possible? There is the statement i=i++;. Please explain why the value of i do not increment.
-5
votes
1 answer

How is the following expression be executed?

What is the output of the following program? #include using namespace std; int main() { int a = 2, b = 4; a++ = b; cout << a << b; return 0; }
Yatharth
  • 15
  • 5