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

Can I Use post increment in function return in C?

can I use post-increment in a function return in C like this? int meta_solve() { //some codes return metaData[head++]; //head is global variable } I asking this question because it showing the different results on windows and mac. thanks…
-1
votes
2 answers

Why the output is showing 3 1 3 can anyone help me in this in C

#include int main() { int i = 1; printf("%d %d %d",++i,i++,i); return 0; }
First last
  • 29
  • 5
-1
votes
1 answer

Why n++==--n always equal to 1?

Why n++==--n always equal to 1? The following code gives output as 1. #include int main(){ int n=10; printf("%d\n",n++==--n); } The output is always 1, no matter what n is.
-1
votes
1 answer

Loop runs one more time than I expected

class BlankIt{ public static void main(String[] args) { int i = 10, j = 20; while(i++ < --j){ System.out.println("\n " + i + " " + j); } System.out.println("\n " + i + " " + j); } } The…
user11718102
-1
votes
1 answer

Java Incremental Oddity

You may have already seen this somewhere, but I couldn't find a question on it. It's just a curiosity but I want to know what exactly is happening under the hood: int j = 0; for (int i = 0; i < 100; i++) { j = j++; } System.out.println(j); The…
-1
votes
4 answers

Why does my program not add numbers until -1 is given?

The following code should prompt the user for prices and add that to a total. If the user inputs -1 the adding loop must terminate and the program should print a total and exit. But for some reason this is not happening. #include int…
sweet
  • 11
  • 3
-1
votes
3 answers

Not getting expected output from this code using logical operators and pre/post increment

I am not getting expected output in the following C code main(){ int i=0,j=-2,k=0,m; if((!i||--j&&k++)&&(i++||j++&&!k++)) { printf("i=%d j=%d k=%d",i,j,k); } return 0; } I got the output in compiler as : i=1 j=-1…
chesslad
  • 171
  • 7
-1
votes
1 answer

Tryiing to overload the post increment operator in c++ in but the answer is not as expected

#include using namespace std; class B{ int temp1; public : void disp() { cout <
piku_baba
  • 59
  • 7
-1
votes
1 answer

C=C++; why the value is not changing of C variable as it remain 0

Why the value of C is not changing when i use c=c++; instruction. Code #include int main() { int t, c=0,d; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); if(n>=50) { c=c++; printf("%d\n",c); } } …
-1
votes
1 answer

Undefined Behaviour in C [with example]

I had been going over a few tricky and unusual behaviour that C code snippets produce, and I came across one that resulted an unusual output. int main() { int i=3; printf("%d%d%d", i, ++i, i++); return 0; } I thought this would have…
-1
votes
1 answer

Output is less than expected after using incrementer operator

I create a class abc and static variable and two function having name setsize in which I set a value and another function I create a getsize to get value in getsize function I increment a value when I call a function its output must be 101 but it…
-1
votes
1 answer

Why count doesn't behave normal in python for loop

I have a text file I'm reading from and just threw a counter on there to make sure I grabbed everything but when I implemented a simple counter it acted weird. It works now but I had to do the following: f = open("street.txt", "r") l = "" count =…
John Verber
  • 745
  • 2
  • 16
  • 31
-1
votes
2 answers

About expressions on while loop

Assume i > 0 is true. Why is this expression: while(i > 0) { printf("Hello \n); i--; }; equal to this expression: while(i--) { printf("Hello \n"); };
Tolis M.
  • 27
  • 9
-1
votes
1 answer

My overloaded post-increment method doesn't work as expected. Why?

I have this C++ class that accepts a day number of the year and converts it to the month-day format. It works fine but my problem with it is that my overloaded post-increment operator doesn't work as expected. I understood that the following…
-1
votes
2 answers

Why post increment and pre increment is equal here?

When I try to use the below code as post-increment or pre-increment of $j the result is always the same. Do you know why? Please tell me. Thank you. "; } ?>
M.S Shohan
  • 132
  • 9