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

Out put of this program .Confused?

So I am stuck with this question. int i=5,a; a=++i + i++ + ++i + i++ - --i; printf("%d",a); According to me 'a' should be 20. a=6+6+8-8 However, on execution I found the answer to be 18. What I am doing wrong? A step by step explanation would be…
-3
votes
2 answers

Pre and post increment in java

I know how pre and post increment operators work, but recently I found out a strange behavior in Java. What i knew so far was (as explained in this answer as well): a = 5; i=++a + ++a + a++; => i=6 + 7 + 7; (a=8) which clearly shows that the ++a…
-3
votes
1 answer

'In any case, follow the guideline "prefer ++i over i++" and you won't go wrong.' What is the reason behind this in C?

I had come across this answer to this question. In one of the line, the author mention's: In any case, follow the guideline "prefer ++i over i++" and you won't go wrong. I know that ++i is slightly faster than i++, but thought that there is no…
Box Box Box Box
  • 5,094
  • 10
  • 49
  • 67
-3
votes
2 answers

Mathematical representation of ++a

We can define a++ as a = a + 1; Which is self-explaining that it makes a copy of a then adds 1 to it and puts the result in a. But can we define ++a the same way? Maybe the answer is very simple but I'm unaware of it.
SSH
  • 1,609
  • 2
  • 22
  • 42
-3
votes
1 answer

How the pre and post increment work in c++?

i want to know if increment/decrement operator results vary from compiler to compiler or it is independent of the compiler. as I am getting different results in different compilers of c/c++ (tested in G++, TDM, gcc) for the same expression.
Vimlesh
  • 109
  • 1
  • 5
-3
votes
1 answer

C Simple Modulo;

int i = 1, j = 2, k; k = i % ++j I don't understand why k would equal 1. I figured it what equal 0 because wouldn't the fraction 1/3 round down to 0? Thank you!
-3
votes
1 answer

Why does the compiler skip some parts of a compound statement

For example in the code below int x,y,z; x=y=z=1; z = ++x && ++y || ++z; cout<
-3
votes
2 answers

Increment Operator Magic in C#

Why is the Output of this code gives the value 100. Please help me to understand this behavior. static void Main(string[] args) { int i = 100; for (int n = 0; n < 100; n++) { i = i++; } …
Akshay Joy
  • 1,765
  • 1
  • 14
  • 23
-3
votes
1 answer

How is the postfix and prefix increment operator evaluated in an expression?

#include "stdafx.h" #include #include using namespace std; int main() { int n = 5; cout<< n++ <<" "<< ++n << " "<< n++; _getch(); return 0; } When I run this program on Visual Studio the output is 7 8 5. I think it is…
user2672697
  • 11
  • 1
  • 1
  • 3
-4
votes
1 answer

I am getting the wrong output when trying post-increment operation on a pointer in C

I am testing out pre- and post-increment on an array using pointer. I use the pointers p and q to access the elements of the array but the issue stems from the last result on pointer p. #include int main(void) { int a[] = {10, 11,…
Monarch
  • 1
  • 1
-4
votes
1 answer

int x = ++n + n++; returns an unexpected value

According to the concept of pre-increment and post-increment operator the output of the following code should be (8+8) = 16, but in the compiler it is evaluated to 17. Please explain with steps. #include using namespace std; int…
-4
votes
1 answer

How to calculate values for -- / ++

I am trying to get the value for the last equation int a = 0, b = 0, c = 0, x = 0, y = 0, z = 0; a = b++ + ++c; printf("a=%d\n", a); x = y + 1 + ++z; printf("x=%d\t", x); printf("b=%d\t", --b); printf("b=%d\t", b++); printf("c=%d\t",…
-4
votes
1 answer

I want to pre-increment an assignment to a variable (pre-increment by value more than 1)?

I want to pre-increment a value assignment in a for loop for (int x=0; x<100; x+=increase){ // loop operation here } The code above post increments the value, however I want to pre increment it. I know I can pre-increment by one with the ++i…
-4
votes
2 answers

what is the difference between ++*var++ and ++Var++?

What is difference between ++*var++ and ++var++ ? why ++*var++ is working while ++var++ results with lvalue required error in C?
-4
votes
1 answer

pre/post increment decrements evaluation in single line

can you please explain me this. I have read almost all questions on stackoverflow undefined behaviour pre/post inc.. dec.. operator precedence/associativity use the parenthesis but results are inconclusive. please explain this i have an…
1 2 3
22
23