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

variable length argument in c program

In the following program #include int main() { int a; a=5; printf("%d %d %d\n", a, a++ , a++); //statement 1 a=5; printf("%d %d %d\n", a, ++a , ++a); //statement 2 return 0; } Output 7 6 5 7 7 7 My question why there is different…
night_hawk
  • 101
  • 1
  • 6
-4
votes
1 answer

l value required as increment operand

Can somebody explain the compilation error in the program #include int main() { int i = 10; printf("%d", ++(-i)); return 0; }
-5
votes
3 answers

Unexpected Output involving array values with post and pre-increment

Shouldn't the output of following program be - 2 3 20 instead it is showing 3 2 15 Can anyone explain the reason behind this? #include main() { int a[5] = {5,1,15,20,25}; int i,j,m; i = ++a[1]; j = a[1]++; m =…
raesrem
  • 55
  • 4
-5
votes
1 answer

how does one determine the behaviour of post increment values when passed to macros

#define man(x,y)((x)>(y))?(x):(y); int main() { int i=10,j,k; j=5; k=0; k=man(++i,j++); printf("%d %d %d",i,j,k); return 0; } The output is: 12 5 12 Can anyone make it clear as to how the value of i,k is 12 and not 11.
-6
votes
2 answers

C: What is the output of the following code? And please explain

int a = 5; if(a==a++){ printf("true 1"); } if(a==++a){ printf("true 2"); } When I run this code, it prints "true 2". I do not understand how. Please help. Also, how is logical equivalence computed in precedence with increment operators?
-6
votes
3 answers

Operator precedence and operator associativity rules in c++

I do not understand why the output of following program is 63: #include int main() { int a = 20; a += a + ++a; std::cout << a; } I was expecting it to be 61. What exactly a += a + ++a; does?
user2747954
  • 97
  • 1
  • 5
  • 16
-6
votes
2 answers

C code, where i have a value of an integer variable and after a pre-increment operation i need to get the output

i=2; i= ++i + ++i + ++i; printf(i) Please give the output with explanation? The answer I'm getting is 12 but it should be 13.
-7
votes
1 answer

looping thru array, increment doesnt work

ARRAY_SIZE[10] = {0}; int i; for(i = 0; i < ARRAY_SIZE; ++i ) { printf("Before assignment %d\n", array_of_ints[i]); } I was expecting the print out result be 0 thru 9, since ++i increments i. And on the second loop it will print out 1,…
-7
votes
1 answer

Pre and Post Increment and Decrement in Java

Day after tomorrow is my exam for Computers (JAVA) and I have a big problem in the above title. I understood what does post and pre increment and decrement means. But I can no understand what to do when the matter comes to a complex, long statement.…
-9
votes
1 answer

I'm having trouble understanding how Post Increment (++), Pre Increment work together in an example

I'm having trouble understanding how Post Increment (++), Pre Increment work together in an example. x++ means add 1 to the variable But I am confused with this example: using namespace std; / run this program using the console pauser or add your…
-13
votes
2 answers

post increment and pre increment operator

Please explain me the outcome of this code. //code a when I run this code on my laptop, value of y is 4. And I think, logically value of y should be 5 because by doing x++ it should return 2 without incrementing as it is post increment and then when…
1 2 3
22
23