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

I don't understand the output of this code

I'm currently learning C, and my teacher gave us some homework. We had to identify the output of some code. I don't understand how y=4. The code is as follows int main() { int w = 3, y = 3; printf("w = %i\n", --w + w--); printf("y =…
Nxt3
  • 1,970
  • 4
  • 30
  • 52
0
votes
1 answer

Meaning of the code in matlab

As am new to mathematica, pls do help me what is happening in the code given in mathematica. I want to write it in matlab. Clear[t, k, w, fg, g]; t = 0; k = 0; For[a = 1, a < 26, t = t1, t1 = t + 8]; g = ((−1)^a+1)∗…
0
votes
3 answers

Preincrement and Postincrement

I've been trying to understand how post and pre increments work lately and I've been over thinking it too much. Does "Product" become 25 after one iteration? Product *=5++ And does "Quotient" become 5/6 after one iteration? Quotient /= ++x
0
votes
5 answers

Behavior of Java Postincrementor

public static void main(String[] args) { int a = 1; int b = a++; System.out.println(b); } Why does the code above print 1? I was told that a++ means you would get the value of a. then increment it. But the code above never…
AvP
  • 359
  • 2
  • 3
  • 14
0
votes
2 answers

post increment and pointer in printf

Can someone please explain why this code is outputing 2 1, I thought post-increment was supposed to be applied after the printf instruction. #include int main() { int i=1; int *p=&i; printf("%d %d\n", *p ,i++); return 0; }
Youssef Bouhjira
  • 1,599
  • 2
  • 22
  • 38
0
votes
1 answer

What happen if I use pre increment and post increment in the same statement?

I've seen an interesting statement today with post-increment and pre-increment. Please consider the following program- #include int main(){ int x, z; x = 5; z = x++ - 5; // increase the value of x after the statement…
aniskhan001
  • 7,981
  • 8
  • 36
  • 57
0
votes
3 answers

Post increment in Java

In this code segment, [1]int i=0; [2]i = i++; [3]System.out.println(i); In line 2, it is executed the expression first (which is assigned 0 to i) and then it should increment the value by 1. In System.out.println(i) , I am getting the answer as 0…
chathura
  • 3,362
  • 6
  • 41
  • 68
0
votes
1 answer

task in increment , decrement , printf() , why these are evaluated in this manner in C

#include #include int main() { int a=3; //case 1 printf("%d %d %d\n",(--a),(a--),(--a));//output is 0 2 0 printf("%d\n",a);//here the final value of 'a' //end of case 1 a=3; //case 2 printf("%d\n",(++a)+(a--)-(--a));//output is…
0
votes
9 answers

C Increment operators

I have compiled the code below in codeblocks and it shows the output 0...0 . But I think its output should be 0...1 because "if" statement is not true here so the statement following the "if" is not executed.Then j is incremented by 1 ( because of…
0
votes
2 answers

PHP serial number on fetched database rows

I am working on a project that fetches certain records from a database and displays in a table. The number of records (rows) fetched depends on my given conditions. All these work just fine for me. My challenge is that I would like to display a…
efraimo
  • 1
  • 3
0
votes
7 answers

Why is there any difference between "++i" and "i++" in a for loop?

It seems to me that for(int i = 0; i < 2; i++) and for(int i = 0; i < 2; ++i) should not do the same thing. For the second example it's more logic to me that i should equals 1 since the begining of the loop.
0
votes
4 answers

Pre and post increment in a for loop

Is it more performant to do a pre-increment vs a post-increment in a for loop in java ? Sample code : for (int i=0; i<10; i++) and for (int i=0; i<10; ++i) I notice that when i do a pre-increment, the execution time is lesser that when i do the…
lokoko
  • 5,785
  • 5
  • 35
  • 68
0
votes
1 answer

postincrement operator interesting behaviour in Math.min()

I have a question, In Java, does Math.min bind tighter than ++? Let me illustrate with an example and maybe someone can explain to me why I get the results I get. Here's a method I run: private static void testIncrement() { int x=10; …
Adrian
  • 5,603
  • 8
  • 53
  • 85
0
votes
2 answers

Why does post increment operator not work although preincrement does work in this code?

I am really new to programming (I'm an electronics and comm. engineer) and I am not able to figure out why one program works and the other one doesn't. I'd like to get a good understanding of recursive functions before going any further with my…
umayneverknow
  • 190
  • 1
  • 3
  • 13
0
votes
1 answer

If there any difference using ++variable instead of variable++ in a for loop?

Possible Duplicate: Is there a performance difference between i++ and ++i in C++? Difference between i++ and ++i in a loop? I know that a++ return the original value of a and then add one to a, while ++a increment a by one and return a. But I…
Aikanáro
  • 867
  • 3
  • 20
  • 42