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
3 answers

What does arr++ mean in a function "int f(int arr[])"?

I was looking at this code and understood pretty much all of it except one thing: what does Arr1++ means? What does it do to the array? since Arr1 is not just a normal variable like int.. bool theSameElements(int Arr1[], int Arr2[], int size) { …
Cocoboom
  • 35
  • 1
  • 7
-1
votes
1 answer

Why does overloading the post increment operator in C++ call the constructor twice?

I was playing with overloading different operators and added print statements to watch what was happening. When I overloaded the post increment operator, I saw that the constructor was being called twice, but I don't understand why. #include…
yamex5
  • 195
  • 1
  • 11
-1
votes
2 answers

Maximum sum of lengths of non-overlapping contiguous subarrays

I'm trying to implement amazon interview question. Find the maximum sum of lengths of non-overlapping contiguous subarrays with k as the maximum element. Ex: Array: {2,1,4,9,2,3,8,3,4} and k = 4 Ans: 5 {2,1,4} => Length = 3 {3,4} => Length = 2 So,…
Jayesh
  • 4,755
  • 9
  • 32
  • 62
-1
votes
2 answers

Increment in java

Can anybody explain it to me why the value of n1 is not increasing by 1 in this case, or in other words why the mathematical operation isn't showing 1. package com.company; public class Main { public static void main(String[] args) { …
Shpend Palushi
  • 597
  • 8
  • 21
-1
votes
1 answer

Variable does not increment though did not define

As you guys see, I did not define the variable "n_students" therefore it should be able to increment without any problem, but it does not. It also does not increment when I put it inside the user define function, so what seems to be the problem…
Anh Minh Tran
  • 341
  • 1
  • 3
  • 11
-1
votes
4 answers

C Increment Operator Explanation

On executing this piece of C command, the output of num is 7. I was expecting it to be 6, can anyone explain why and how it turns out to be 7? #include int main() { int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int i = 0, num =…
-1
votes
3 answers

Post-increment operator does not increment variable until after evaluation

I am searching for a reason for why increment operator doesn't increment the numeric value in the place where I set the innerHTML value, like below:
var a = 14; document.getElementById("php").innerHTML = a++;//the result will…
mina
  • 141
  • 1
  • 10
-1
votes
1 answer

Post-increment within a self-assignment, different results between VS2013 and GCC

The codes in this Post-increment within a self-assignment, testing with C++. However I get different result between VS2013 and GCC4.8.4 int cc = 42; cc = cc++; cout << cc << endl; The result of VS2013 is 43, but the result of GCC is 42. It confuse…
zangw
  • 43,869
  • 19
  • 177
  • 214
-1
votes
1 answer

Post Increment in C++

I know the concept of post increment but how does it apply to the follow? The output of t is 10. How to explain the undefined behavior? int a = 2; int b = 3; int t; t = a++ * (a+b);
MLAC
  • 129
  • 2
  • 10
-1
votes
2 answers

Rules for post-increment and pre-increment operations in java

Oh, I've something missed with this example... int a=1; int b=1; int c=1; System.out.println(a+++b---c++); Is not it the same as next? System.out.println( (a++) + (b--) - (c++) ); It seems the result is 0, but that's definitely wrong, so what's…
user4446735
-1
votes
4 answers

Why is the output `0` in this case?

#include int main(void) { int i; int *p = (int *) malloc(5 * sizeof(int)); for (i=0; i<10; i++) *(p + i) = i; printf("%d ", *p++); return 0; } So, I ran this code. Now I was told here that Why won't the…
John Lui
  • 1,434
  • 3
  • 23
  • 37
-1
votes
2 answers

post and pre increment in for loop. string length without library function in C

I am trying to find Length of a string w/o using library function. char card[16]; //card number in char array. unsigned int cardno[16]={0}; //card number in int array for calculations. int i,length=0,len; printf("Credit Card…
mukesh.kumar
  • 1,100
  • 16
  • 30
-1
votes
1 answer

Why does variable only increment once in Java code?

I am making a game where a player ('P') starts on a 2d array of dashes at [0][0]. The player is prompted to enter the size of the array, and then enter an action (left, right, up, down, or exit). When that action is entered, 'P' is supposed to move…
DevOpsSauce
  • 1,319
  • 1
  • 20
  • 52
-1
votes
1 answer

Does scope affects on pre and post increment in function call?

Firstly, this is my first question here so forgive me for any mistakes.. I came across this program below : #include main() { int i=2; void add(); add(i++,--i); printf("/ni=%d ",i); } void add(int a ,int b) { printf("/na=%d…
shalnich
  • 3
  • 1
-1
votes
4 answers

Two post increment questions

I have this code : static void Main(string[] args) { int a = 1; int b = 1; int c; //task A c = a; Console.WriteLine(c); c = a++; Console.WriteLine(c); …
wendy
  • 161
  • 3
  • 14