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

How a=3 and b=4?

I found an interesting Programing question : What will be the values of a,b,c,f after executing this programe ? int i=0,a=0,b=0,c=0,f=0; while(i<=5){ switch(i++){ case 1:++a; case 2:++b; break; case 3: case 4:++c;a++;b++; …
Arjun Sunil Kumar
  • 1,781
  • 3
  • 28
  • 46
0
votes
2 answers

I embedded a countdown timer in this code, but it didn

package com.android.tapme; import android.os.Bundle; import android.app.Activity; import android.widget.*; import android.view.*; public class TapMe extends Activity { private int countValue=0; @Override public void onCreate(Bundle…
Karthik Balakrishnan
  • 4,353
  • 6
  • 37
  • 69
0
votes
1 answer

Implementation of increment-operators in android

i did some tests with pre- and post-incrementation, to figure if there are performance or power-consumption differences within the two operators on android. i did not find any differences. the basic thesis is well explained here:…
-1
votes
2 answers

Why is pre and post increment operator not working in recursion?

I have the following: public static void main(String[] args){ Screen.clear(); System.out.println(depth(5,0)); } public static int depth(int n, int depth){ System.out.println(depth); if(n == 0)return…
DCR
  • 14,737
  • 12
  • 52
  • 115
-1
votes
2 answers

Why isn't the ++y part executing?

So here is the question I am given , I need to tell the output : #include using namespace std; int main() { int x = 10; int y = 20; if(x++ > 10 && ++y > 20 ){ cout << "Inside if "; } else{ cout << "Inside else "; …
Virat
  • 77
  • 7
-1
votes
1 answer

Prefix and postfix operator

#include int main() { int x=5, y; y=x+++x; printf("%d", x); printf("%d", y); } What I found is that postfix increment has higher precedence than prefix. Hence y=x+++x; y=(x++)+x; y=10 x=6 But when I execute the program…
-1
votes
1 answer

How the value of m is 2?

How the value of m is 2 after execution as i is postfix ? int main() { int i,m; int a[5]={8,10,1,14,16}; i=++a[2]; m=a[i++]; cout<
-1
votes
2 answers

C language: When [variables++] in array[ ] work? For example, when array[j++] = arr[i]. It is doing j++ first or do = arr[i] first?

disclaimer this is not my code and this code is from Remove Duplicate Elements from an Array in C - Javatpoint What I want to know is in the Example 2 coding part. (I edit code a bit for me or you can see the code clearly.) /* program to delete the…
-1
votes
2 answers

Getting wrong output for a++ +b according to lexical analysis when the program is printed along with a+++b

I wrote the following C program to find the output for a+++b #include int main() { int a=5, b=2; printf("%d",a+++b); } And I'm getting the output as 7 which is correct according to lexical analysis. Apart from that I wrote a…
-1
votes
1 answer

Why is the output of the following program showing compile time error?

Why is the output of the following program showing compile time error? Please explain "lvalue required" #include int main() { int a=5; printf("%d", ++a++); return 0; }
-1
votes
1 answer

Increment behaviour using char pointer

When i write copy ( s1++, s2++ ) instead of copy ( ++s1, ++s2 ) nothing happens.What's the problem? #include void copy ( char *, char * ); int main ( void ) { char st[] = "hello"; char st2[10]; copy ( st, st2 ); printf (…
dumb
  • 21
  • 3
-1
votes
1 answer

b=b++ assignment unexpected result

I wrote this text code int b=5; int main() { b=b++; printf("b = %d\n",b); return 0; } and I expected it to print "b = 6"; however, the result is "b = 5", i.e. b is not incremented. I know b=b++ is not a good practice but just to…
Guille
  • 326
  • 2
  • 10
-1
votes
1 answer

Array[i] = i++;

int main() { int arr[5]= {55}, i=0; while (i<5) { arr[i]= i++; } for(i=0; i<5; i++) printf("%d, ", arr[i]); return 0; } why is the output ( 55,0,1,2,3) Not ( 0,1,2,3,4) Ps: I'm using GCC compiler
Sherif Beshr
  • 23
  • 1
  • 8
-1
votes
3 answers

What is the principle of this code with i++?

Code #include using namespace std; int main() { int i = 1; while (i < 10) if (i++ % 2 == 0) cout << i << endl; return 0; } The output is 3 5 7 9 Since i is 1, I thought that the if statement satisfies…
Corin-2
  • 7
  • 1
-1
votes
1 answer

When does a function call copy its pass-by-value arguments relative to the argument sequences?

I would like to understand this code snippet as much as the undefined behavior permits it: int i = 0; printf("%d %d %d", i, ++i, i++); output: 2 2 0 From what I can tell: a comma , defines a sequence the actual printing happens when all of the…