Questions tagged [decrement]

Subtracting one from the value of a variable, generally with the use of an decrement operator.

Subtracting one from the value of a variable, generally with the use of an decrement operator(--).

425 questions
-4
votes
5 answers

Prevent the risk when using decrement/increment postfix operator in C++?

Recently I found the risk when using st like this: int i = 10; int sum = 0; while ( i-- ){ sum = sum + i; It actually get sum = 9 + 8 + 7 + .. + 1. So it lacks 10 in total. But I prefer this way of coding, it's fast and professional. Is there…
Duc Tran
  • 6,016
  • 4
  • 34
  • 42
-4
votes
1 answer

How to trace a C++ program by hand?

#include int fun(int &x,int y=10) { if(x%y==0) return (++x); else return (y--); } int main() { int p=10,q=13; q=fun(p,q); cout<
-4
votes
2 answers

Incrementing/decrementing entirely a float type number

What I'm trying to do is to increment the entire float value, for…
-4
votes
2 answers

Java input value for variable from scanner isn't applying to variable in method

I'm fairly new to Java so bear with me. I'm making a recursive method in Java that allows me to input a number X and have the system print each value in decrements of 2 until it reaches 1. (I'll have to add a rule that the scanner can only take odd…
Dotol
  • 376
  • 1
  • 4
  • 19
-4
votes
4 answers

Why is the -- operator not subtracting from the value when executed?

Why is the decrement operator -- not bringing the value down by 1 when executed? int a = 20; int c ; c = a--; Inspecting the value of c now, it should be 19, yet it comes out as 20. What am I missing?
-4
votes
1 answer

Minus input number in JTextField from stored Values

I'm trying to make a stock system, when a user enters a number of an item they want it's subtracted from the total available. How would I do this? I'm a beginner so I'm not too sure For My code below trying to get the input of sofa and minus it…
-4
votes
9 answers

increment operator more purpose?

I was wondering if the increment and decrement operators ( ++ -- ) have more purpose to it than its plain use to make the code more simple maybe: i++; is more efficient than: i = i + 1; ?
alfalfa
  • 147
  • 1
  • 8
-5
votes
3 answers

Does brackets matter in a combination of post decrement or increment like this one: x+=(x++)+(++x);

For the following program is it necessary to have the brackets in the statement of post-increment or decrement public class sample { public void f1() { int x=4; x+=(x++)+(++x); System.out.println(x); } } ^^Is this equal to public…
bhargav
  • 1
  • 2
-5
votes
3 answers

How did this output come from this program?

Hello pro coders of stackoverflow community, I'm still a beginner and I need help understanding the problem below: int main() { int x=4,y=0; while(x>=0) { if(x==y) break; else …
-5
votes
2 answers

Increment and Decrement operators

I am confused about the output of this program: #include int main() { int i=2; while(i + 1?--i:14) printf("\n%d", i); return 0; } The output of the above program is printing 1 and not printing 1 and then 0 When i-- is…
user3485153
  • 27
  • 2
  • 5
-6
votes
1 answer

Post decrement, what is a-- * a--?

int a = 10; System.out.println(a-- * a--); what will be the output of these print statement and why?? in post decrement we actually observe that the value is used before getting change but here I am getting in one of the operator (a--) is 10…
-6
votes
1 answer

Increment and decrement operators in one statement in C

I know it is theoretically undefined behavior and of course bad style. This is the example of a school (I am not the pupil). But why do I get 7 (example a) resp. 1 (example b) out of this operation: Online…
Christian
  • 3,503
  • 1
  • 26
  • 47
-6
votes
1 answer

What will be the working of this statement in program of java?

The Question is if c=12; c=c++ + ++c; what will be the working solution for this? like how would it be ex(12+13)something like this please specify what would be (c++)and what would be (++c)
-6
votes
1 answer

What is the output of this code? Am i missing something here?

void main() { int num, a=15; num = ----a--; cout<
Niranjan Dixit
  • 115
  • 3
  • 12
-6
votes
1 answer

Does using the ++ or -- operator on different variables in the same expression invoke UB?

I wanted to know whether using the increment(++) or the decrement(--) operator on different variables in the same expression undefined behavior; Such as int i=1,j=2; int k=i++ + j++; In the above code,the value of k is 3 in clang,GCC and in vc.
Spikatrix
  • 20,225
  • 7
  • 37
  • 83
1 2 3
28
29