Increment And Decrement Operators In C | Lesson-24 | Learn C Programming From Subhash K U

preview_player
Показать описание
In this video, we'll be learning everything about increment and decrement operators in detail.

To watch the next video of this C programming Series, click on the link below.

If you haven't yet watched the previous lesson of this series, make sure you watch it before moving further on this C programming series by clicking on the link below.

To be a part of our exclusive community on Telegram who are following this C programming series with you, make sure you click on the link below and join our Telegram Channel.

For notes, you can also refer the online book written by Subhash K U by following the link below.

Рекомендации по теме
Комментарии
Автор

Pre- increment means 1st it is increment the value and then assigned to the variable.
Post increment means 1st the value is assigned and then it is incremented.

durgasyamalaperuri
Автор

When we keep the increment operator before the variable then it is called pre increment operator and when we keep the increment operator after the variable then it is called post increment operator.
Output: a=3
b=11

shreyamukkawar
Автор

when we place increment operator after the variable name it becomes post increment operator
when we place increment operator before the variable name it becomes pre increment operator

b=--a
b= a - 1= a
b= 6-1 =a
b= 5=a
(a=5)

therefore b = - -a results in 5 in the 1st case, then the value of a becomes 5
in the 2nd case --a results in 4
now value of a=4
in the 3rs case --a results in 3
now the value of a is 3

evaluating b=--a+--a+--a we get
b = 5+4+3
b=12
a=3

dhanyam
Автор

Ans: a= 3, b= 12
Preincrement is frst we have to increment the value then assign
Postincrement is frst we assign a value and then increment

savithag
Автор

when we keep increment after the variable is called post increment operator
When we keep increment before the variable is called pre increment operator

bhanuprasannareddy
Автор

Sir can you please show the steps involved in calculating the value of b...
As I get b =12 (I guess, I made some mistake)
and working on computer I get b=11

dhanyam
Автор

A=3 B=12
Pre increment means first we to increase the value by one and use.post increment means first we need to use that variable and incremented by one

sushanthchandan
Автор

Hi, By using the volatile keyword for the variable a, I was getting the output value of b was 12, without volatile it was 11.

Program 1:
#include <stdio.h>
int main() {
    // Write C code here
    volatile int a = 6;
    int b = 0;
    b = --a + --a + --a;
    printf("Value of b: %d , a: %d", b, a);
    return 0;
}

Ouput : Value of b: 12, a: 3

Program 2:
#include <stdio.h>
int main() {
    // Write C code here
    int a = 6;
    int b = 0;
    b = --a + --a + --a;
    printf("Value of b: %d , a: %d", b, a); 
    return 0;
}

Output : Value of b: 11, a: 3

sravanakumar
Автор

Intially a=6 after pre decrement a=5 +a=4 +a=3
So, b=5+4+3=12
a=3

thegeethaart
Автор

Sir please help in solving today's assignment.

dipalipotdar
Автор

Sir unable to get the desired output
How it is 11?

abhishekgoswami
Автор

Sir don't we follow any associvity?

ashwini
Автор

Difference between pre- increment and post- increment:
Pre- increment: here 1st we have to do increment and then assign the value.
Post increment : here 1st assign the value and then increment the value

Problem: a= 6;
b = --a + --a + --a;
Output is a=3
b= 11
1.a=6
b=--a;
a=5, b=5

2. b= --a + --a
5+4
But here we have to take update value 4 of the right side value 4 assign to the left side value

b = --a + -- a
b= 4 +4
b =8
b= --a + --a + --a
b= 4+4+3
b= 8+3
b=11
a=3, b=11
We have to do like this

kasimanvenky