postfix vs. prefix increment operator | C Programming Tutorial

postfix vs. prefix increment operator | C Programming Tutorial

Portfolio Courses

3 года назад

14,433 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

David Landivar
David Landivar - 06.10.2023 18:12

It’s incredible how you can be told the concept in dozens of ways, but the simplest and most effective one comes from the smartest mind. This doesn’t have to be hard, but if it becomes hard when the person instructing is not intelligent like you. Thank you so much l. Also thank you for not doing an Indian accent

Ответить
hikiNeeto
hikiNeeto - 07.06.2023 11:15

result = i++ * 10;
I wonder which one happens first in the statement above:
i) incrementing i
ii) storing the value of (i * 10) in the variable "result"

Ответить
just curious
just curious - 28.04.2023 12:22

So I was just trying to understand why the postfix operator has the highest precedence among all other operators according to cppreference , so I tried this expression :
int i = 1 ;
int result = i++*10*2 ; // I thought it's equivalent to something like this (i*10)++*2 = 22
but the result is 20 which mean the variable i never incremented ,
ChatGPT explanation :
" The equivalent expression to i++*10*2 using parentheses is (i++) * 10 * 2.

This is because the post-increment operator ++ has a higher precedence than multiplication * operator in C, which means that i++ is evaluated first, and then the multiplication takes place.

By using parentheses to explicitly group the i++ expression, we ensure that the post-increment operator is applied to i before the multiplication takes place, just as it was in the original expression. "

Ответить
Nhật An
Nhật An - 17.01.2023 08:59

thank you so much

Ответить
tiagoalv3s
tiagoalv3s - 06.07.2022 21:56

Excellent explanation, I finally got it! Thank you!

Ответить
Md. Redwan Hossain
Md. Redwan Hossain - 14.05.2022 03:24

You can use make demo && ./demo
No need to type with gcc for compiling C code. make command is easier and requires less words.

Ответить
Bishal Subba
Bishal Subba - 09.04.2022 21:41

Nice and your voice is like Thanos 😅

Ответить
bir yazılım hikayesi
bir yazılım hikayesi - 19.11.2021 15:34

You aremagnificient thank you i appreciate it

Ответить
abdelaziz el hayyany
abdelaziz el hayyany - 24.10.2021 16:30

And I just found your playlist ( examples in C)
It's amazing 🤩
Keep going ❤️♥️

Ответить