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

pre-increment and post-increment in printf

int main() { int value = 4321; int *ptrVal = &value; printf("%d %d",++value,(*(int*)ptrVal)--); return 0; } How does pre-increment/post increment works in above print statement ? And why is answer 4321 4321 ?
Rohit
  • 6,941
  • 17
  • 58
  • 102
-2
votes
1 answer

I was doing code on operator overloading . while i encoutered a strange behaviour can any one explain it?

** Pre Increment ** #include using namespace std; class demo { int i; public: demo (int b = 0) { i = b; } void display() { cout<<"Number is " <
-2
votes
2 answers

why doesn't the result of an array member changed when have assigned it?

when I did something like this: int arr[]={11, 12, 13, 14, 15}; int *p=arr; *(p++) += 100; The result of arr[1] was still 12,why?
-2
votes
1 answer

I don't understand how to interpret ++a * ++a

Can anybody tell me how the answer of this code is 16 25 #include #define sqr(x) ++x * ++x int main() { int a = 3, z; z = ++a * ++a; a -= 3; printf("%d %d", sqr(a), z); return 0; }
-2
votes
1 answer

Strange behavior of multiplying a pre-increment variable to itself in c++

sorry if my question is duplicate or not worth answering. I have been the following code that produces the result that I am not understanding how. int x=5; int y; y = ++x * ++x; cout<
Waheed
  • 7
  • 2
-2
votes
2 answers

Why pre increment is not evaluated

#include int main(){ int a=5,b=-7,c=0,d; d=++a && ++b || ++c; printf("%d %d %d %d",a,b,c,d); } Here value of c should increase to 1 but it is giving 0, why?
-2
votes
3 answers

Priority operators in C

I found this text (source: https://education.cppinstitute.org/) and I'm trying to understand the second instruction. Can you answer the question of what distinguishes these two instructions? c = *p++; and c = (*p)++; We can explain: the first…
Martin
  • 66
  • 5
-2
votes
2 answers

unexpected behaviour of pre and post increment in c language gcc compiler

If n has the value 5 then output: printf("%d %d", n++, ++n); //should be 5 and 7 But I get as output 6 and 7.
-2
votes
3 answers

Js magic need explanation

I'm trying to solve this magic in js: var a = 1; console.log(a++ + ++a); It returns 4 and I can understand that it's 1+3 but what is the sequence of this?
Vadym
  • 548
  • 2
  • 8
  • 21
-2
votes
2 answers

Macro anomaly in c++/g++

The code below should return the value 216 but it returns 392 that is (7*7*8) . Can somebody please explain me how? #include #define cube(x) (x*x*x) using namespace std; int main() { int x=5; cout<
xeon
  • 895
  • 9
  • 15
-2
votes
6 answers

Preincrement in character pointers

I was toying with the concept of array pointers. I wrote this simple program: #include int main (int argc, char **argv){ char s[] = "Hello world!\n"; char *i; for (i = s; *i; ++i){ printf(i); } return…
Morteza R
  • 2,229
  • 4
  • 20
  • 31
-2
votes
3 answers

What is the difference between a++ and a+1?

I was writing a small piece of code wherein I had to increment value of a variable 'j' if the condition matched. for(int i=0;i
Backspace
  • 292
  • 1
  • 4
  • 17
-2
votes
1 answer

Pre/post increment with #define in c

I wrote a small piece of code in which I used #define with increment operator. The code is #include #define square(a) ((a)*(a)) int main () { int num , res ; scanf ("%d",&num ) ; res = square ( num++ ) ; printf ( "The…
BharathYes
  • 787
  • 2
  • 9
  • 25
-2
votes
2 answers

pre-increment and post- increment

#include int main() { int a = 10; ++a = 20; printf("a = %d", a); getchar(); return 0; } The output obtained for the above code is : a=20; when run as C++ code. #include int main() { int a = 10; …
Trinity
  • 17
  • 3
-2
votes
3 answers

please explain the output the following c program

Could anyone please explain the result of the following C program? #include int main() { int i=2; printf("%d %d %d",i,i++,++i); return 0; } How is the output 4 3 4?