Questions tagged [pre-increment]

For issues relating to defining or performing pre increment operations.

Pre-increment operators increase the value of their operand by 1 (or another specified amount), and the value of the operand in the expression is the operand's value after the increment operation.

342 questions
-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

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
-1
votes
2 answers

Why change UB that will always work as intended?

In the legacy code base I'm working on, I discovered the line n = ++n % size; that is just a bad phrasing of the intended n = (n+1) % size; as deduced from the surrounding code and runtime-proved. (The latter now replaces the former.) But since…
Wolf
  • 9,679
  • 7
  • 62
  • 108
-1
votes
1 answer

Does promotion occur before increment in Java?

I've seen this question in OCA questions and need to know why it outputs 90 and not 100. Here is the code: int x = 9; long y = x * (long) (++x); System.out.println(y); So, what I think this would do is, firstly, increment x (because that's what…
user218046
  • 623
  • 6
  • 20
-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
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
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
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

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

Pre increment and post increment function call

#include int main() { void add(); int i=2; add(i++,--i); print("%d",i) } void add(int a,int b) { print("%d %d",a,b); } /*what are a and b's value i am actually not getting the answer why b is 2 */
-1
votes
1 answer

Why lvalue required as increment operand?

I know those precedence and associativity at all, but I cant able to sort the error correctly for this expression. c=b|i+++++j;
-1
votes
2 answers

Output of the program((confused))

Can you explain the output of the following program: #include using namespace std; int main() { int a=10; int x=(a++)+(++a)+(a++)+(a++)+(++a); cout<
-1
votes
1 answer

Unary operation are sometimes suicidal.Mess up with C code

Code in C language. #include #define PRODUCT(x) ( x * x * x) int main() { int i =5,k; k = PRODUCT( ++i ); printf("i is :%d ",k); return 0; } My Question is why i is : 392? According to me output should be 336. (because 6 * 7 * 8 =…
-1
votes
1 answer

Java nested for loop incrementing second loop by first for loop?

Hi I'm learning Java and found a solution that is pretty neat, but I'm interested in a particular line of code in the 2nd for loop. I wouldn't know who to ask because I'm not in school for Java yet so I'm asking here, but anyway: for (int i = 0; i <…
JasonC
  • 19
  • 2
  • 7
-1
votes
1 answer

Different between x++ and ++x

I've known that primary operator (x++) is different form unary operator (++x) when combine with another operator in a statement. But I wonder whether those two operator is same when leave them alone on the statement. I mean about compiled code,…
Tu Tran
  • 1,957
  • 1
  • 27
  • 50