C Programming Tutorial 34 - Increment and Decrement Operators

preview_player
Показать описание


~~~~~~~~~~~~~~~ CONNECT ~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~ SUPPORT ME ~~~~~~~~~~~~~~

🅑 Bitcoin - 3HnF1SWTzo1dCU7RwFLhgk7SYiVfV37Pbq
🅔 Eth - 0x350139af84b60d075a3a0379716040b63f6D3853
Рекомендации по теме
Комментарии
Автор

Thank you so much for your explanation! I have been incrementing in Flowgorithm, and I understood what it did, but I didn't understand the logic behind how an operator was incrementing. Your explanation of how pizzasToEat + 1 is assigned back to the variable pizzasToEat was very helpful and allowed me to understand the process! Seems super simple, but for some reason it was confusing to me, but as soon as you explained it, it all became clear.

AlianaR
Автор

Thanks, Caleb ...your videos abou C programming are realy usefull. I am beginner and i like your ability to express C language a simply way.

romanpolicar
Автор

Thanks so much for this wonderful tutorial series! I’m watching your videos incrementally…

PunmasterSTP
Автор

I had created my own program to play around with and was briefly confused with the output, so I changed my first variable to a constant, and got 'read-only' error. I rewound the video and heard the mention of 'operators that could change the value of operands.' I was watching at 1.75x speed, so, thats my fault! But, I really think you should put more emphasis on the fact that both variables are getting altered. I knew about Inc/Decs from when I was learning C#, but I didn't realize(or forgot) they still changed the value if used in an assignment. I could see this really tripping up someone trying to learn a language for the first time....anyway, I wrote a program to demonstrate each of the Pre/Post Incr/Decrementors and my variable 'cups' seems to never change, which I thought it would, as it's the operand that ++ and -- are operating on. The rest of my variables are named to reflection the operation, and those values ARE reflecting the changes to cup; it's just cup's value doesn't seem to change. Any help with what I'm missing here would be appreciated.


edit: figured out what I did wrong ...this program helps to illustrate what is happening:

#include <stdio.h>

int main()
{

int cups = 5;


printf("\n\t Starting value of cups is %i\n\n", cups);


//post incrementing
int postInc = cups++; //passes current value, THEN increments
printf("\nPost Incrementing cups: %i\n\n", postInc);
printf("The current value of cups is %i\n\n", cups);

//pre incrementing
int preInc = ++cups; //increments, THEN passes value
printf("Pre Incrementing cups: %i\n\n", preInc);
printf("The current value of cups is %i\n\n", cups);

//post decrementing
int postDec = cups--; //passes value, THEN decrements
printf("Post Decrementing cups: %i\n\n", postDec);
printf("The current value of cups is %i\n\n", cups);

//pre decrementing
int preDec = --cups; //decrements, THEN passes value

printf("Pre Decrementing cups: %i\n\n", preDec);


printf("The ending value of cups is %i\n\n", cups);
}

Sorthious
Автор

#include <stdio.h>

int main(){
int bottles = 99;
while(bottles>0){
printf(”There are %i bottles of beer on the wall! Take one down, pass it around, %i bottles of beer on the wall!\n”, bottles, --bottles);
}
return 0;
}

auralluring
Автор

I'm almost done with the play list

PeculiarJake
Автор

Okay, ++ and -- need their own videos. They do not act like other operators.

++ will change the value of the variable, not just ADD to it. ++ actually changes the variable. So if you type X = 5 and Y = ++X or X++, X's value will now be 6 for the rest of the program.

The only question is if you're using X's new value or old value for the expression. Y = ++X will use X's new value. Y = X++ will use X's old value for this equation, but if you print X's value after Y = X++, you will find that although Y is equal to old X, X's value is now plus one more than what it returned before.

jadoaesra
Автор

thank you so much. i appreciate your clear explanation

emmanuelonuoha
Автор

Isn't there a '+=' operator included in this lesson? It's an increment by value. Example:
pizzasToEat += 5; // this increments the pizzas by a value of 5, and is much shorter than writing out the whole thing:

pizzasToEat = pizzasToEat + 5;

JerBearTube
Автор

So im a little confused putting the PizzasToeat++ computes it after ....but where? does it add it to the next time you goto use pizzaToeat again?

filip
Автор

What is the point of a Postfix increment if its not even applied?

_nightowl
Автор

what is the difference of using void main and int main ?

arvinarulthevaralarulnatha
Автор

I'm so lucky I found his channel T.T

jahzielperalta
Автор

will be valid see :


output = pizzasToEat++


as:


output = pizzasToEat = pizzasToEat + 1;


first assign pizzasToEat to output and the perform the operation on the right?

santanacasas
Автор

youre the best i love you so much i hope you have the best life omg:(

LK-dnwm
Автор

Because printf(“pizzasToEat: %i\n”, pizzasToEat); was ran second is why it was 99?

DjehutimasAsarRa
Автор

At first I was like Then I tried some test code of my own and could clearly see what happens. Maybe this might help someone....

Example 1:
int

Code behaves like the following:



Example 2:

int

Code behaves like the following:




Example 3:

int adjusted_variable=- -original_variable;

Code behaves like the following:



Example 4:

int -;

Code behaves like the following:



markjones