Difference between revisions of "C-and-C++/C2/Increment-And-Decrement-Operators/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 5: Line 5:
  
 
|-
 
|-
| 00.02
+
| 00.01
 
| Welcome to the spoken tutorial on '''Increment and Decrement Operators in C and C++'''.
 
| Welcome to the spoken tutorial on '''Increment and Decrement Operators in C and C++'''.
  
 
|-
 
|-
|  00.09
+
|  00.08
 
| In this tutorial, we will learn about:
 
| In this tutorial, we will learn about:
  
 
|-
 
|-
|  00.11
+
|  00.10
 
|Increment and decrement operators
 
|Increment and decrement operators
  
++ eg. a++ which is postfix increment operator.
+
|-
 +
|  00.12
 +
|++ eg. a++ which is postfix increment operator.
  
++a which is prefix increment operator.
+
|-
 +
|  00.18
 +
|++a which is prefix increment operator.
  
- - eg. a- -  is  a postfix decrement operator.
 
  
- -a   is a prefix decrement operator.We will also learn about Type casting.
+
|-
 +
|  00.22
 +
- - . a- -  is  a postfix decrement operator.
 +
 
  
 
|-
 
|-
| 00.36
+
| 00.27
 +
|  - -a  is a  prefix decrement operator.
 +
 
 +
|-
 +
|  00.31
 +
|We will also learn about Type casting.
 +
 
 +
|-
 +
| 00.35
 
|  To record this tutorial, I am using: '''Ubuntu 11.10''' as the operating system  
 
|  To record this tutorial, I am using: '''Ubuntu 11.10''' as the operating system  
  
 
|-
 
|-
|  00.41
+
|  00.40
 
|'''gcc''' and '''g++ Compiler''' version''' 4.6.1 '''in''' Ubuntu'''.
 
|'''gcc''' and '''g++ Compiler''' version''' 4.6.1 '''in''' Ubuntu'''.
  
 
|-
 
|-
|  00.49
+
|  00.48
 
|  The '''++''' operator increases the existing value of the operand by one.
 
|  The '''++''' operator increases the existing value of the operand by one.
 +
  
 
|-
 
|-
|  00.54  
+
|  00.54
|'''a++''' and '''++a''' are equivalent to '''a = a + 1'''.
+
|'''a++''' and '''++a''' are equivalent to ''a = a + 1''.
  
 
|-
 
|-
| 01.01
+
| 01.00
 
|The '''--''' operator decreases the existing value of the operand by one.
 
|The '''--''' operator decreases the existing value of the operand by one.
  
 
|-
 
|-
|  01.07
+
|  01.06
 
|'''a--''' and '''--a''' are equivalent to '''a = a - 1'''.
 
|'''a--''' and '''--a''' are equivalent to '''a = a - 1'''.
  
 
|-
 
|-
| 01.14
+
| 01.13
 
|  I will now demonstrate the use of increment and decrement operators with the help of a C program.
 
|  I will now demonstrate the use of increment and decrement operators with the help of a C program.
  
 
|-
 
|-
|  01.20
+
|  01.19
 
|I have already made the program, so I'll explain the code.
 
|I have already made the program, so I'll explain the code.
  
 
|-
 
|-
|  01.26
+
|  01.25
 
|Here, we have the code for increment and decrement operators in '''C.'''
 
|Here, we have the code for increment and decrement operators in '''C.'''
  
Line 65: Line 80:
  
 
|-
 
|-
|  01.36
+
|  01.35
 
|This way we will be able to observe the changes in the value of '''a'''.
 
|This way we will be able to observe the changes in the value of '''a'''.
  
 
|-
 
|-
|  01.40
+
|  01.39
 
|It will thus give us a better idea about the working of the operators.
 
|It will thus give us a better idea about the working of the operators.
  
 
|-
 
|-
|  01.48
+
|  01.47
 
|  Let's see how the '''postfix''' increment operator works.
 
|  Let's see how the '''postfix''' increment operator works.
  
 
|-
 
|-
| 01.52
+
| 01.51
 
|The output of this printf statement is 1.
 
|The output of this printf statement is 1.
  
 
|-
 
|-
|  01.56
+
|  01.55
|The value will change.
+
|The value wont change.
  
 
|-
 
|-
| 01.58
+
| 01.57
 
|This is because the postfix operation occurs after the operand is evaluated.
 
|This is because the postfix operation occurs after the operand is evaluated.
  
 
|-
 
|-
|  02.05
+
|  02.04
 
|If an operation is performed on '''a++''', it is performed on the current value of '''a'''.
 
|If an operation is performed on '''a++''', it is performed on the current value of '''a'''.
  
 
|-
 
|-
|  02.11
+
|  02.10
 
|After that the value of '''a''' is incremented.
 
|After that the value of '''a''' is incremented.
  
 
|-
 
|-
| 02.18
+
| 02.17
 
|  Now if we see the value of''' a '''here, it has been incremented by 1.
 
|  Now if we see the value of''' a '''here, it has been incremented by 1.
  
 
|-
 
|-
| 02.28
+
| 02.27
 
|  We again initialize a to 1 so as to reflect on the changes.
 
|  We again initialize a to 1 so as to reflect on the changes.
  
 
|-
 
|-
|  02.36
+
|  02.35
 
|  We now come to the prefix increment operators
 
|  We now come to the prefix increment operators
  
 
|-
 
|-
|  02.39
+
|  02.38
 
|  This printf statement prints 2 on the screen.
 
|  This printf statement prints 2 on the screen.
  
 
|-
 
|-
|  02.43
+
|  02.42
 
|  This is because a prefix operation occurs before the operand is evaluated.
 
|  This is because a prefix operation occurs before the operand is evaluated.
  
 
|-
 
|-
|  02.50
+
|  02.49
 
|  So the value of a is first incremented by 1 and then it is printed.
 
|  So the value of a is first incremented by 1 and then it is printed.
  
 
|-
 
|-
|  02.59
+
|  02.58
 
|  We again print a's value to see that there are no further changes.
 
|  We again print a's value to see that there are no further changes.
  
 
|-
 
|-
|  03.04
+
|  03.03
 
|  Now lets check by executing this code.
 
|  Now lets check by executing this code.
  
 
|-
 
|-
|  03.08 
+
|  03.07
|  I will comment out the following lines. Type /* ,*/
+
|  I will comment out the following lines. Type /*, */
  
 
|-
 
|-
Line 137: Line 152:
  
 
|-
 
|-
|  03.23
+
|  03.22
 
|  I have saved my file as '''incrdecr.c'''.
 
|  I have saved my file as '''incrdecr.c'''.
  
 
|-
 
|-
|  03.30
+
|  03.29
 
|  Open the terminal window by pressing '''Ctrl, Alt and T '''keys''' '''simultaneously.
 
|  Open the terminal window by pressing '''Ctrl, Alt and T '''keys''' '''simultaneously.
  
 
|-
 
|-
|  03.36
+
|  03.35
|  To compile, type the following on the terminal  '''gcc incrdecr.c -o incr'''. Press enter.
+
|  To compile, type the following on the terminal  '''gcc space incrdecr dot c space minus o space incr'''. Press enter.
  
 
|-
 
|-
|  03.52
+
|  03.51
|  To execute the code, type '''./incr''''. Press enter.
+
|  To execute the code, type ''./incr''. Press enter.
  
 
|-
 
|-
Line 157: Line 172:
  
 
|-
 
|-
|  04.02
+
|  04.01
 
|  This is the output when you print a++
 
|  This is the output when you print a++
  
 
+
|-
 
+
|  04.06
|-
+
|  04.06
+
 
|  This is the output when you print ++a.
 
|  This is the output when you print ++a.
  
 
|-
 
|-
|  04.10
+
|  04.09
 
|  We  can see that the result is as discussed before.
 
|  We  can see that the result is as discussed before.
  
Line 173: Line 186:
 
|-
 
|-
 
| 04.13
 
| 04.13
| Now Coming back to the rest of the code.
+
| Now Coming back to the rest of the program.
  
 
|-
 
|-
|  04.17
+
|  04.16
 
|  I will now explain the postfix and prefix  decrement operators.
 
|  I will now explain the postfix and prefix  decrement operators.
  
 
|-
 
|-
|  04.22
+
|  04.21
|   remove the multiline comment from here and here .
+
| Remove the multiline comments from here and here .
  
 
   
 
   
 
|-
 
|-
 
|  04.29
 
|  04.29
| We now again assign the value of '''1''' to '''a'''.
+
| We now again assign the value of ''1'' to ''a''.
  
 
|-
 
|-
|  04.36
+
|  04.35
 
|  This '''printf''' statement outputs the value of 1 as explained previously.
 
|  This '''printf''' statement outputs the value of 1 as explained previously.
  
 
|-
 
|-
|  04.42
+
|  04.40
 
|  A's value will be decremented after a-- is evaluated as its a postfix expression.
 
|  A's value will be decremented after a-- is evaluated as its a postfix expression.
 
|-
 
|  04.51
 
|  This printf statements output the value of 1 as explained previously
 
  
  
 
|-
 
|-
|  04.57
+
|  04.47
|  A's value is now decremented by 1 after a-- is evaluated  .As its a post fix expression
+
|-
+
|  05.03
+
 
|  The next statement prints a's value as o.
 
|  The next statement prints a's value as o.
 +
 
|-
 
|-
05.07
+
04.51
| A's value has now decremeted being1.
+
| A's value has now being decremeted by 1.
  
 
|-
 
|-
05.10
+
04.54
 
|  We now have the prefix decrement operator.
 
|  We now have the prefix decrement operator.
  
 
|-
 
|-
05.14
+
04.58
 
|  Output of this printf statement would be 0.
 
|  Output of this printf statement would be 0.
  
 
|-
 
|-
|  05.17
+
|  05.00
 
|  As it is a prefix operation.
 
|  As it is a prefix operation.
  
 
|-
 
|-
|  05.21
+
|  05.05
 
|  The prefix operation occurs before the operand is evaluated.
 
|  The prefix operation occurs before the operand is evaluated.
  
 
|-
 
|-
|  05.25
+
|  05.09
 
|  This printf statements output is 0.
 
|  This printf statements output is 0.
  
 
|-
 
|-
|  05.28
+
|  05.11
 
|  No further changes have being made to a's value.
 
|  No further changes have being made to a's value.
  
 
|-
 
|-
|  05.31
+
|  05.15
 
|  Type return 0;  And close the ending curly bracket
 
|  Type return 0;  And close the ending curly bracket
  
 
|-
 
|-
| 05.37
+
| 05.21
 
|  Click on '''Save.'''
 
|  Click on '''Save.'''
  
 
|-
 
|-
|  05.40
+
|  05.24
 
|  Switch back to the terminal.
 
|  Switch back to the terminal.
  
 
|-
 
|-
|  05.43
+
|  05.27
|  To compile type the following on the terminal; gcc incrdecr.c -o incr. Press Enter.
+
|  To compile type the following on the terminal; gcc space incrdecr dot c space minus o space incr. Press Enter.
  
 
|-
 
|-
|  05.58
+
|  05.42
To execute type, ./incr.Press Enter.
+
Execute type, ./incr.Press Enter.
 
+
 
+
  
 
|-
 
|-
06.08
+
05.52
 
|  This is the output when you print a--
 
|  This is the output when you print a--
  
 
   
 
   
 
 
|-
 
|-
06.12
+
05.56
 
|  This is the output when you print --a  
 
|  This is the output when you print --a  
  
 
   
 
   
 
|-
 
|-
06.15
+
05.59
 
|  So, now we see how the increment and  decrement operator works.
 
|  So, now we see how the increment and  decrement operator works.
  
 
|-
 
|-
|  06.21
+
|  06.05
 
| If we want to write the same program in C++.
 
| If we want to write the same program in C++.
  
 
|-
 
|-
|  06.23
+
|  06.07
 
|  I can make a few changes to the above C code.
 
|  I can make a few changes to the above C code.
  
 
|-
 
|-
|  06.26
+
|  06.10
 
|  Let me go back to the editor.  
 
|  Let me go back to the editor.  
  
 
|-
 
|-
|  06.29
+
|  06.13
 
|  Here is the '''C++ '''file with the necessary code.
 
|  Here is the '''C++ '''file with the necessary code.
  
  
 
|-
 
|-
|  06.33
+
|  06.16
 
|  Notice that the header is different from the C file header.
 
|  Notice that the header is different from the C file header.
  
 
|-
 
|-
|  06.37
+
|  06.20
|  We have the '''using namespace '''statement here.
+
|  We have the '''using namespace '''statement also.
  
 
|-
 
|-
|  06.40
+
|  06.24
|  Also, note that the output statement in C++ is '''cout'''.
+
|  Also, note that the output statement in C++ is ''cout''.
  
 
|-
 
|-
|  06.45
+
|  06.28
 
|  So, apart from these differences, the two codes are very similar.
 
|  So, apart from these differences, the two codes are very similar.
  
 
|-
 
|-
|  06.49
+
|  06.33
|  Save the file. The file is saved with an extension '''.cpp'''
+
|  Save the file. The file is saved with an extension ''.cpp''
  
 
|-
 
|-
| 06.56
+
| 06.40
 
|  Let's compile the code.
 
|  Let's compile the code.
  
 
|-
 
|-
|  06.58
+
|  06.42
|  Open the terminal and type  '''g++ incrdecr.cpp -o incr'''. Press Enter.
+
|  Open the terminal and type  '''g++ space incrdecr dot cpp space minus o space incr'''. Press Enter.
  
 
|-
 
|-
|  07.16
+
|  07.00
| To execute Type  '''./ incr'''.Press Enter.
+
| Execute Type  '''./ incr'''.Press Enter.
  
 
|-
 
|-
|  07.23
+
|  07.07
 
|  The output is displayed on the screen:
 
|  The output is displayed on the screen:
  
Line 328: Line 332:
 
   
 
   
 
|-
 
|-
|  07.27
+
|  07.10
 
|  So, we see the output is identical to the C program.
 
|  So, we see the output is identical to the C program.
  
 
|-
 
|-
|  07.31
+
|  07.15
 
| We now have the concept of typecasting.
 
| We now have the concept of typecasting.
  
 
|-
 
|-
|  07.33
+
|  07.17
 
|  It is implemented the same way in both '''C '''and '''C++'''.
 
|  It is implemented the same way in both '''C '''and '''C++'''.
  
 
|-
 
|-
|  07.38
+
|  07.22
 
|  Typecasting is a used to make a variable of one type, act like another type.
 
|  Typecasting is a used to make a variable of one type, act like another type.
  
 
|-
 
|-
| 07.43
+
| 07.27
 
|  Typecasting is done by enclosing the data type you want within parenthesis.
 
|  Typecasting is done by enclosing the data type you want within parenthesis.
  
 
|-
 
|-
|  07.49
+
|  07.33
 
|  This cast is put in front of the variable you want to cast.
 
|  This cast is put in front of the variable you want to cast.
  
 
|-
 
|-
|  07.54
+
|  07.38
 
|  This '''typecast''' is valid for one single operation only.
 
|  This '''typecast''' is valid for one single operation only.
  
 
|-
 
|-
|  07.58
+
|  07.42
 
|  Now '''a''' will behave as a '''float''' variable for a single operation.
 
|  Now '''a''' will behave as a '''float''' variable for a single operation.
  
 
|-
 
|-
| 08.03 
+
| 07.47
|  Here is an example I have already created.
+
|  Here is an example that I have already created.
  
 
|-
 
|-
08.06
+
07.50
 
|  I shall now explain the code.
 
|  I shall now explain the code.
  
 
|-
 
|-
08.11
+
07.54
| We first declare the variables '''a''' and '''b''' as integer and '''c''' as float.
+
| We first declare variables '''a''' and '''b''' as integer and '''c''' as float.
  
 
|-
 
|-
|  08.16
+
|  08.00
|  '''a''' is assigned the value 5. '''b''' is assigned the value 2.
+
|  '''a''' is assigned the value of  5. '''b''' is assigned the value of 2.
  
 
|-
 
|-
|  08.22
+
|  08.06
 
|  We will perform operations on '''a''' and '''b'''.
 
|  We will perform operations on '''a''' and '''b'''.
  
 
|-
 
|-
| 08.26
+
| 08.10
 
|  We divide '''a''' by '''b'''. The result of division is stored in '''c'''.
 
|  We divide '''a''' by '''b'''. The result of division is stored in '''c'''.
  
 
|-
 
|-
|  08.30
+
|  08.14
 
|  We have used '''%.2f''' to denote a precision of 2 decimal places.
 
|  We have used '''%.2f''' to denote a precision of 2 decimal places.
  
 
|-
 
|-
|  08.35
+
|  08.20
 
|  The result displayed will be 2.00 against the expected result of 2.50.
 
|  The result displayed will be 2.00 against the expected result of 2.50.
  
 
|-
 
|-
|  08.41
+
|  08.25
 
|  The fractional part has been truncated as both the operands '''a''' and '''b''' are integers.
 
|  The fractional part has been truncated as both the operands '''a''' and '''b''' are integers.
  
 
|-
 
|-
|  08.47
+
|  08.31
 
|  To perform real division one of the operands will have to be type cast to float.
 
|  To perform real division one of the operands will have to be type cast to float.
  
 
|-
 
|-
|  08.51
+
|  08.35
 
|  Here we are typecasting '''a '''to float. '''c''' now holds the value of real division.
 
|  Here we are typecasting '''a '''to float. '''c''' now holds the value of real division.
  
 
|-
 
|-
|  08.57
+
|  08.41
 
|  Now the result of real division is displayed. The answer is 2.50 as expected.
 
|  Now the result of real division is displayed. The answer is 2.50 as expected.
  
 
|-
 
|-
| 09.03 
+
| 08.47
 
|  Type''' return 0;'''  and close the  ending curly bracket.
 
|  Type''' return 0;'''  and close the  ending curly bracket.
  
 
|-
 
|-
| 09.07
+
| 08.51
 
|  Click on '''Save'''. Save the file with '''.c''' extension.
 
|  Click on '''Save'''. Save the file with '''.c''' extension.
  
 
|-
 
|-
09.11
+
08.55
 
|  I have saved my file as '''typecast.c'''.
 
|  I have saved my file as '''typecast.c'''.
  
 
|-
 
|-
09.15
+
08.59
 
|  Open the terminal.
 
|  Open the terminal.
  
 
|-
 
|-
|  09.17
+
|  09.01
|  To compile, type '''gcc typecast.c -o type'''.Press Enter.
+
|  To compile, type '''gcc space typecast dot c space minus o space type'''.Press Enter.
  
 
|-
 
|-
|  09.33
+
|  09.17
 
|  to execute, type '''./type'''.Press Enter.  
 
|  to execute, type '''./type'''.Press Enter.  
  
 
|-
 
|-
|  09.41
+
|  09.25
 
| The output is displayed on the screen.
 
| The output is displayed on the screen.
  
 
   
 
   
 
|-
 
|-
|  09.44
+
|  09.27
| looking at the two values we see the effects of typecasting.
+
| Looking at the two values we see the effects of typecasting.
  
 
|-
 
|-
|  09.48
+
|  09.32
 
|  We will summarize the tutorial now.  
 
|  We will summarize the tutorial now.  
  
 
|-
 
|-
|  09.50
+
|  09.34
 
|  In this tutorial we learnt,
 
|  In this tutorial we learnt,
  
 
|-
 
|-
|  09.52
+
|  09.36
 
|  How  to  use the increment and decrement operators.
 
|  How  to  use the increment and decrement operators.
  
 
|-
 
|-
|  09.56
+
|  09.40
|  We learn't about the form  Postfix  and Prefix   
+
|  We learn't about the forms, Postfix  and Prefix   
  
  
 
|-
 
|-
10.00
+
09.44
 
| Also we  learnt about typecasting and how it is used.
 
| Also we  learnt about typecasting and how it is used.
  
 
|-
 
|-
10.04
+
09.47
| As an assignment:
+
|  As an assignment:
  
 
|-
 
|-
10.05
+
09.49
|  Write a program to solve the following expression, '''(a\b) + (c\d)'''
+
|  Write a program to solve the following expression, a divided by b plus c divided by d
  
 
|-
 
|-
10.12
+
09.56
 
|  The values of '''a, b, c''' and '''d''' are taken as input from the user.
 
|  The values of '''a, b, c''' and '''d''' are taken as input from the user.
  
 
|-
 
|-
|  10.17
+
|  10.01
 
|  Use typecasting to perform real division.
 
|  Use typecasting to perform real division.
  
 
|-  
 
|-  
|  10.21
+
|  10.05
 
|  Watch the video available at the following link  
 
|  Watch the video available at the following link  
 +
 
|-
 
|-
|  10.24
+
|  10.08
 
|  It summarises the Spoken Tutorial project  
 
|  It summarises the Spoken Tutorial project  
 +
 
|-
 
|-
| 10.27
+
| 10.10
 
|  If you do not have good bandwidth, you can download and watch it  
 
|  If you do not have good bandwidth, you can download and watch it  
 
  
  
 
|-
 
|-
|  10.321
+
|  10.15
 
|  The Spoken Tutorial Project Team  
 
|  The Spoken Tutorial Project Team  
 +
 
|-
 
|-
|  10.34
+
|  10.17
 
|  Conducts workshops using spoken tutorials  
 
|  Conducts workshops using spoken tutorials  
 +
 
|-
 
|-
|  10.36
+
|  10.20
 
|  Gives certificates for those who pass an online test  
 
|  Gives certificates for those who pass an online test  
 +
 
|-
 
|-
|  10.410
+
|  10.24
 
|  For more details, please write to contact at spoken hyphen tutorial dot org
 
|  For more details, please write to contact at spoken hyphen tutorial dot org
 
 
  
 
|-
 
|-
| 10.49
+
| 10.33
 
|Spoken Tutorial Project is a part of the Talk to a Teacher project  
 
|Spoken Tutorial Project is a part of the Talk to a Teacher project  
 +
 
|-
 
|-
|  10.53
+
|  10.37
 
|  It is supported by the National Mission on Education through ICT, MHRD, Government of India   
 
|  It is supported by the National Mission on Education through ICT, MHRD, Government of India   
  
 
|-
 
|-
11.00
+
10.44
|  More information on this Mission is available at  spoken hyphen tutorial dot org slash NMEICT hyphen Intro  
+
|  More information on this Mission is available at  spoken hyphen tutorial dot org slash NMEICT hyphen Intro  
 
+
 
+
  
 
|-
 
|-
11.11
+
10.55
 
|  This is Ritwik Joshi from IIT Bombay.  
 
|  This is Ritwik Joshi from IIT Bombay.  
  

Revision as of 15:33, 27 November 2013

Time' Narration


00.01 Welcome to the spoken tutorial on Increment and Decrement Operators in C and C++.
00.08 In this tutorial, we will learn about:
00.10 Increment and decrement operators
00.12
+ eg. a++ which is postfix increment operator.
00.18
+a which is prefix increment operator.
00.22 - - . a- - is a postfix decrement operator.


00.27 - -a is a prefix decrement operator.
00.31 We will also learn about Type casting.
00.35 To record this tutorial, I am using: Ubuntu 11.10 as the operating system
00.40 gcc and g++ Compiler version 4.6.1 in Ubuntu.
00.48 The ++ operator increases the existing value of the operand by one.


00.54 a++ and ++a are equivalent to a = a + 1.
01.00 The -- operator decreases the existing value of the operand by one.
01.06 a-- and --a are equivalent to a = a - 1.
01.13 I will now demonstrate the use of increment and decrement operators with the help of a C program.
01.19 I have already made the program, so I'll explain the code.
01.25 Here, we have the code for increment and decrement operators in C.
01.30 Here, I have taken an integer variable a that holds the value 1.
01.35 This way we will be able to observe the changes in the value of a.
01.39 It will thus give us a better idea about the working of the operators.
01.47 Let's see how the postfix increment operator works.
01.51 The output of this printf statement is 1.
01.55 The value wont change.
01.57 This is because the postfix operation occurs after the operand is evaluated.
02.04 If an operation is performed on a++, it is performed on the current value of a.
02.10 After that the value of a is incremented.
02.17 Now if we see the value of a here, it has been incremented by 1.
02.27 We again initialize a to 1 so as to reflect on the changes.
02.35 We now come to the prefix increment operators
02.38 This printf statement prints 2 on the screen.
02.42 This is because a prefix operation occurs before the operand is evaluated.
02.49 So the value of a is first incremented by 1 and then it is printed.
02.58 We again print a's value to see that there are no further changes.
03.03 Now lets check by executing this code.
03.07 I will comment out the following lines. Type /*, */
03.19 Click on Save.
03.22 I have saved my file as incrdecr.c.
03.29 Open the terminal window by pressing Ctrl, Alt and T keys simultaneously.
03.35 To compile, type the following on the terminal gcc space incrdecr dot c space minus o space incr. Press enter.
03.51 To execute the code, type ./incr. Press enter.
03.59 The output is displayed on the screen,
04.01 This is the output when you print a++
04.06 This is the output when you print ++a.
04.09 We can see that the result is as discussed before.


04.13 Now Coming back to the rest of the program.
04.16 I will now explain the postfix and prefix decrement operators.
04.21 Remove the multiline comments from here and here .


04.29 We now again assign the value of 1 to a.
04.35 This printf statement outputs the value of 1 as explained previously.
04.40 A's value will be decremented after a-- is evaluated as its a postfix expression.


04.47 The next statement prints a's value as o.
04.51 A's value has now being decremeted by 1.
04.54 We now have the prefix decrement operator.
04.58 Output of this printf statement would be 0.
05.00 As it is a prefix operation.
05.05 The prefix operation occurs before the operand is evaluated.
05.09 This printf statements output is 0.
05.11 No further changes have being made to a's value.
05.15 Type return 0; And close the ending curly bracket
05.21 Click on Save.
05.24 Switch back to the terminal.
05.27 To compile type the following on the terminal; gcc space incrdecr dot c space minus o space incr. Press Enter.
05.42 Execute type, ./incr.Press Enter.
05.52 This is the output when you print a--


05.56 This is the output when you print --a


05.59 So, now we see how the increment and decrement operator works.
06.05 If we want to write the same program in C++.
06.07 I can make a few changes to the above C code.
06.10 Let me go back to the editor.
06.13 Here is the C++ file with the necessary code.


06.16 Notice that the header is different from the C file header.
06.20 We have the using namespace statement also.
06.24 Also, note that the output statement in C++ is cout.
06.28 So, apart from these differences, the two codes are very similar.
06.33 Save the file. The file is saved with an extension .cpp
06.40 Let's compile the code.
06.42 Open the terminal and type g++ space incrdecr dot cpp space minus o space incr. Press Enter.
07.00 Execute Type ./ incr.Press Enter.
07.07 The output is displayed on the screen:


07.10 So, we see the output is identical to the C program.
07.15 We now have the concept of typecasting.
07.17 It is implemented the same way in both C and C++.
07.22 Typecasting is a used to make a variable of one type, act like another type.
07.27 Typecasting is done by enclosing the data type you want within parenthesis.
07.33 This cast is put in front of the variable you want to cast.
07.38 This typecast is valid for one single operation only.
07.42 Now a will behave as a float variable for a single operation.
07.47 Here is an example that I have already created.
07.50 I shall now explain the code.
07.54 We first declare variables a and b as integer and c as float.
08.00 a is assigned the value of 5. b is assigned the value of 2.
08.06 We will perform operations on a and b.
08.10 We divide a by b. The result of division is stored in c.
08.14 We have used %.2f to denote a precision of 2 decimal places.
08.20 The result displayed will be 2.00 against the expected result of 2.50.
08.25 The fractional part has been truncated as both the operands a and b are integers.
08.31 To perform real division one of the operands will have to be type cast to float.
08.35 Here we are typecasting a to float. c now holds the value of real division.
08.41 Now the result of real division is displayed. The answer is 2.50 as expected.
08.47 Type return 0; and close the ending curly bracket.
08.51 Click on Save. Save the file with .c extension.
08.55 I have saved my file as typecast.c.
08.59 Open the terminal.
09.01 To compile, type gcc space typecast dot c space minus o space type.Press Enter.
09.17 to execute, type ./type.Press Enter.
09.25 The output is displayed on the screen.


09.27 Looking at the two values we see the effects of typecasting.
09.32 We will summarize the tutorial now.
09.34 In this tutorial we learnt,
09.36 How to use the increment and decrement operators.
09.40 We learn't about the forms, Postfix and Prefix


09.44 Also we learnt about typecasting and how it is used.
09.47 As an assignment:
09.49 Write a program to solve the following expression, a divided by b plus c divided by d
09.56 The values of a, b, c and d are taken as input from the user.
10.01 Use typecasting to perform real division.
10.05 Watch the video available at the following link
10.08 It summarises the Spoken Tutorial project
10.10 If you do not have good bandwidth, you can download and watch it


10.15 The Spoken Tutorial Project Team
10.17 Conducts workshops using spoken tutorials
10.20 Gives certificates for those who pass an online test
10.24 For more details, please write to contact at spoken hyphen tutorial dot org
10.33 Spoken Tutorial Project is a part of the Talk to a Teacher project
10.37 It is supported by the National Mission on Education through ICT, MHRD, Government of India
10.44 More information on this Mission is available at spoken hyphen tutorial dot org slash NMEICT hyphen Intro
10.55 This is Ritwik Joshi from IIT Bombay.

Thank you for joining.