Difference between revisions of "C-and-C++/C2/Increment-And-Decrement-Operators/English-timed"
From Script | Spoken-Tutorial
(Created page with '{| border=1 || ''Time''' || '''Narration''' |- | 00.02 | Welcome to the spoken tutorial on '''Increment and Decrement Operators in C and C++'''. |- | 00.09 | In this tutori…') |
|||
Line 6: | Line 6: | ||
|- | |- | ||
| 00.02 | | 00.02 | ||
− | | | + | | '''C અને C++ માં ઇન્ક્રીમેન્ટ અને ડીક્રીમેન્ટ ઓપરેટર''' પરના સ્પોકન ટ્યુટોરીયલમાં તમારું સ્વાગત છે. |
|- | |- | ||
| 00.09 | | 00.09 | ||
− | | | + | |આ ટ્યુટોરીયલમાં આપણે શીખીશું: |
|- | |- | ||
| 00.11 | | 00.11 | ||
− | | | + | |ઇન્ક્રીમેન્ટ અને ડીક્રીમેન્ટ ઓપરેટર |
− | ++ | + | ++ દા.ત. a++ જે પોસ્ટફિક્સ ઇન્ક્રીમેન્ટ ઓપરેટર છે. |
− | ++a | + | ++a જે પ્રીફિક્સ ઇન્ક્રીમેન્ટ ઓપરેટર છે. |
− | - - | + | - - દા.ત. a-- જે પોસ્ટફિક્સ ડીક્રીમેન્ટ ઓપરેટર છે. |
− | - - | + | - -a જે પ્રીફિક્સ ડીક્રીમેન્ટ ઓપરેટર છે. આપણે ટાઇપ કાસ્ટિંગ વિશે પણ જાણીશું. |
|- | |- | ||
| 00.36 | | 00.36 | ||
− | | | + | | આ ટ્યુટોરીયલ રેકોર્ડ કરવા માટે, હું ઓપરેટિંગ સિસ્ટમ તરીકે '''ઉબુન્ટુ 11.10''' , |
|- | |- | ||
| 00.41 | | 00.41 | ||
− | |'''gcc''' | + | |'''gcc''' અને ઉબુન્ટુમાં '''g++ કમ્પાઈલર''' આવૃત્તિ ''' 4.6.1 ''' નો ઉપયોગ કરી રહ્યી છું. |
|- | |- | ||
| 00.49 | | 00.49 | ||
− | | | + | | '''++''' ઓપરેટર, ઓપરેન્ડની હાલની વેલ્યુને એક દ્વારા વધારે છે. |
|- | |- | ||
| 00.54 | | 00.54 | ||
− | |'''a++''' | + | |'''a++''' અને '''++a''' એ '''a = a + 1''' સમાન છે. |
|- | |- | ||
| 01.01 | | 01.01 | ||
− | | | + | |'''--''' ઓપરેટર, ઓપરેન્ડની હાલની વેલ્યુને એક દ્વારા ઘટાડે છે. |
|- | |- | ||
| 01.07 | | 01.07 | ||
− | |'''a--''' | + | |'''a--''' અને '''--a''' એ '''a = a - 1''' સમાન છે. |
|- | |- | ||
| 01.14 | | 01.14 | ||
− | | | + | | હવે હું C પ્રોગ્રામ ની મદદથી સાથે ઇન્ક્રીમેન્ટ અને ડીક્રીમેન્ટ ઓપરેટરનો ઉપયોગનું નિદર્શન કરીશ. |
|- | |- | ||
| 01.20 | | 01.20 | ||
− | | | + | |મેં પહેલેથી જ પ્રોગ્રામ બનાવ્યો છે, તો હું કોડ સમજાવીશ. |
|- | |- | ||
| 01.26 | | 01.26 | ||
− | | | + | |અહીં આપણી પાસે '''C''' માં ઇન્ક્રીમેન્ટ અને ડીક્રીમેન્ટ ઓપરેટર માટેનો કોડ છે. |
|- | |- | ||
| 01.30 | | 01.30 | ||
− | | | + | | અહીં, મેં એક ઈન્ટીજર વેરિયેબલ લીધો છે જે '''1''' વેલ્યુ ધરાવે છે. |
|- | |- | ||
| 01.36 | | 01.36 | ||
− | | | + | |આ રીતે આપણે '''a''' ની વેલ્યુમાં થતા ફેરફારોનું અવલોકન કરવા માટે સમર્થ થતું. |
|- | |- | ||
| 01.40 | | 01.40 | ||
− | | | + | |આમ આ આપણને ઓપરેટર્સના કામ વિશે વધુ સારી રીતે વિચાર આપશે. |
|- | |- | ||
| 01.48 | | 01.48 | ||
− | | | + | |ચાલો '''પોસ્ટફિક્સ''' ઇન્ક્રીમેન્ટ ઓપરેટર કેવી રીતે કામ કરે છે તે જોઈએ. |
|- | |- | ||
| 01.52 | | 01.52 | ||
− | | | + | |આ printf સ્ટેટમેન્ટનું આઉટપુટ 1 છે. |
|- | |- | ||
| 01.56 | | 01.56 | ||
− | | | + | |વેલ્યુ બદલાશે. |
|- | |- | ||
| 01.58 | | 01.58 | ||
− | | | + | |કારણ કે ઓપરેન્ડના મૂલ્યાંકન થાય પછી પોસ્ટફિક્સ ઓપરેશન થાય છે. |
|- | |- | ||
| 02.05 | | 02.05 | ||
− | | | + | |જો ઓપરેશન '''a++''' પર થાય છે તો તે '''a''' ની વર્તમાન વેલ્યુ પર થાય છે. |
|- | |- | ||
| 02.11 | | 02.11 | ||
− | | | + | |ત્યાર પછી '''a''' ની વેલ્યુ વધે છે. |
|- | |- | ||
| 02.18 | | 02.18 | ||
− | | | + | | હવે જો આપણે અહીં '''a''' ની વેલ્યુ જોઈએ, તો તે અહીં 1 દ્વારા વધેલ છે. |
|- | |- | ||
| 02.28 | | 02.28 | ||
− | | | + | | આપણે a ને ફરીથી 1 થી ઈનીશ્યલાઈઝ કરીશું તેથી ફેરફારો પર અસર થાય. |
|- | |- | ||
| 02.36 | | 02.36 | ||
− | | | + | |હવે આપણે પ્રિફિક્સ ઇન્ક્રીમેન્ટ ઓપરેટરો વિષે શીખીશું. |
|- | |- | ||
| 02.39 | | 02.39 | ||
− | | | + | | આ printf સ્ટેટમેન્ટ સ્ક્રીન ઉપર 2 પ્રિન્ટ કરે છે. |
|- | |- | ||
| 02.43 | | 02.43 | ||
− | | | + | |કારણ કે ઓપરેન્ડના મૂલ્યાંકન થાય પછી પ્રીફિક્સ ઓપરેશન થાય છે. |
|- | |- | ||
| 02.50 | | 02.50 | ||
− | | | + | | તેથી a ની વેલ્યુ પ્રથમ 1 દ્વારા વધે છે અને પછી તે પ્રિન્ટ થયેલ છે. |
|- | |- | ||
| 02.59 | | 02.59 | ||
− | | | + | | આપણે કોઈ ફેરફારો છે કે નહીં તે જોવા માટે a ની વેલ્યુ ફરી પ્રિન્ટ કરી છે. |
|- | |- | ||
| 03.04 | | 03.04 | ||
− | | | + | | હવે આ કોડ એકઝીક્યુટ કરી તપાસીએ. |
|- | |- | ||
| 03.08 | | 03.08 | ||
− | | | + | | હું નીચેની લીટીઓ કમેન્ટ કરીશ. ટાઇપ કરો / *, * / |
|- | |- | ||
| 03.19 | | 03.19 | ||
− | | | + | | '''Save''' ઉપર ક્લિક કરો. |
|- | |- | ||
| 03.23 | | 03.23 | ||
− | | | + | | મેં મારી ફાઈલ '''incrdecr.c''' તરીકે સંગ્રહ કરી છે. |
|- | |- | ||
| 03.30 | | 03.30 | ||
− | | | + | | '''Ctrl, Alt અને T '''કીઝ''' એકસાથે દબાવી ટર્મિનલ વિન્ડો ખોલો. |
|- | |- | ||
| 03.36 | | 03.36 | ||
− | | | + | | કમ્પાઈલ કરવા માટે, ટર્મિનલ ઉપર નીચે આપેલ ટાઇપ કરો, '''gcc incrdecr.c -o incr'''. એન્ટર ડબાઓ. |
|- | |- | ||
| 03.52 | | 03.52 | ||
− | | | + | | કોડ એક્ઝીક્યુટ કરવા માટે, ટાઇપ કરો, '''./incr''''. એન્ટર ડબાઓ. |
|- | |- | ||
| 03.59 | | 03.59 | ||
− | | | + | | આઉટપુટ સ્ક્રીન ઉપર દ્રશ્યમાન થાય છે. |
|- | |- | ||
| 04.02 | | 04.02 | ||
− | | | + | |તમે a++ પ્રિન્ટ કરો છો ત્યારે આઉટપુટ આ આવે છે. |
− | + | ||
− | + | ||
|- | |- | ||
| 04.06 | | 04.06 | ||
− | | | + | | તમે ++a પ્રિન્ટ કરો છો ત્યારે આઉટપુટ આ આવે છે. |
|- | |- | ||
| 04.10 | | 04.10 | ||
− | | | + | | આપણે જોઈ શકીએ છીએ કે પરિણામ પહેલા ચર્ચા કર્યું હતું તે પ્રમાણે છે. |
|- | |- | ||
| 04.13 | | 04.13 | ||
− | | | + | | હવે બાકીના કોડ ઉપર પાછા આવીએ. |
|- | |- | ||
| 04.17 | | 04.17 | ||
− | | | + | |હું હવે પોસ્ટફિક્સ અને પ્રિફિક્સ ડીક્રીમેન્ટ ઓપરેટરો સમજાવીશ. |
|- | |- | ||
| 04.22 | | 04.22 | ||
− | | | + | | અહીં અને અહીં થી મલ્ટી લાઇન કમેન્ટ રદ કરો. |
|- | |- | ||
| 04.29 | | 04.29 | ||
− | | | + | | આપણે હવે ફરીથી '''1 ''' વેલ્યુ ને '''a''' માં અસાઇન કરીએ. |
|- | |- | ||
| 04.36 | | 04.36 | ||
− | | | + | | '''printf''' સ્ટેટમેન્ટ પહેલાં સમજાવ્યા મુજબ 1 ની વેલ્યુ આઉટપુટમાં આપે છે. |
|- | |- | ||
| 04.42 | | 04.42 | ||
− | | | + | | a ની વેલ્યુ a-- ના મૂલ્યાંકન પછી ધટશે કારણ કે તે પોસ્ટફિક્સ એક્સપ્રેશન છે. |
|- | |- | ||
| 04.51 | | 04.51 | ||
− | | | + | | '''printf''' સ્ટેટમેન્ટ પહેલાં સમજાવ્યા મુજબ 1 ની વેલ્યુ આઉટપુટમાં આપે છે. |
− | + | ||
|- | |- | ||
| 04.57 | | 04.57 | ||
− | | | + | | a ની વેલ્યુ a-- ના મૂલ્યાંકન પછી ૧ દ્વારા ધટશે કારણ કે તે પોસ્ટફિક્સ એક્સપ્રેશન છે. |
+ | |||
|- | |- | ||
| 05.03 | | 05.03 | ||
| The next statement prints a's value as o. | | The next statement prints a's value as o. | ||
+ | |||
|- | |- | ||
| 05.07 | | 05.07 |
Revision as of 17:04, 5 September 2013
Time' | Narration
|
00.02 | C અને C++ માં ઇન્ક્રીમેન્ટ અને ડીક્રીમેન્ટ ઓપરેટર પરના સ્પોકન ટ્યુટોરીયલમાં તમારું સ્વાગત છે. |
00.09 | આ ટ્યુટોરીયલમાં આપણે શીખીશું: |
00.11 | ઇન્ક્રીમેન્ટ અને ડીક્રીમેન્ટ ઓપરેટર
++ દા.ત. a++ જે પોસ્ટફિક્સ ઇન્ક્રીમેન્ટ ઓપરેટર છે. ++a જે પ્રીફિક્સ ઇન્ક્રીમેન્ટ ઓપરેટર છે. - - દા.ત. a-- જે પોસ્ટફિક્સ ડીક્રીમેન્ટ ઓપરેટર છે. - -a જે પ્રીફિક્સ ડીક્રીમેન્ટ ઓપરેટર છે. આપણે ટાઇપ કાસ્ટિંગ વિશે પણ જાણીશું. |
00.36 | આ ટ્યુટોરીયલ રેકોર્ડ કરવા માટે, હું ઓપરેટિંગ સિસ્ટમ તરીકે ઉબુન્ટુ 11.10 , |
00.41 | gcc અને ઉબુન્ટુમાં g++ કમ્પાઈલર આવૃત્તિ 4.6.1 નો ઉપયોગ કરી રહ્યી છું. |
00.49 | ++ ઓપરેટર, ઓપરેન્ડની હાલની વેલ્યુને એક દ્વારા વધારે છે. |
00.54 | a++ અને ++a એ a = a + 1 સમાન છે. |
01.01 | -- ઓપરેટર, ઓપરેન્ડની હાલની વેલ્યુને એક દ્વારા ઘટાડે છે. |
01.07 | a-- અને --a એ a = a - 1 સમાન છે. |
01.14 | હવે હું C પ્રોગ્રામ ની મદદથી સાથે ઇન્ક્રીમેન્ટ અને ડીક્રીમેન્ટ ઓપરેટરનો ઉપયોગનું નિદર્શન કરીશ. |
01.20 | મેં પહેલેથી જ પ્રોગ્રામ બનાવ્યો છે, તો હું કોડ સમજાવીશ. |
01.26 | અહીં આપણી પાસે C માં ઇન્ક્રીમેન્ટ અને ડીક્રીમેન્ટ ઓપરેટર માટેનો કોડ છે. |
01.30 | અહીં, મેં એક ઈન્ટીજર વેરિયેબલ લીધો છે જે 1 વેલ્યુ ધરાવે છે. |
01.36 | આ રીતે આપણે a ની વેલ્યુમાં થતા ફેરફારોનું અવલોકન કરવા માટે સમર્થ થતું. |
01.40 | આમ આ આપણને ઓપરેટર્સના કામ વિશે વધુ સારી રીતે વિચાર આપશે. |
01.48 | ચાલો પોસ્ટફિક્સ ઇન્ક્રીમેન્ટ ઓપરેટર કેવી રીતે કામ કરે છે તે જોઈએ. |
01.52 | આ printf સ્ટેટમેન્ટનું આઉટપુટ 1 છે. |
01.56 | વેલ્યુ બદલાશે. |
01.58 | કારણ કે ઓપરેન્ડના મૂલ્યાંકન થાય પછી પોસ્ટફિક્સ ઓપરેશન થાય છે. |
02.05 | જો ઓપરેશન a++ પર થાય છે તો તે a ની વર્તમાન વેલ્યુ પર થાય છે. |
02.11 | ત્યાર પછી a ની વેલ્યુ વધે છે. |
02.18 | હવે જો આપણે અહીં a ની વેલ્યુ જોઈએ, તો તે અહીં 1 દ્વારા વધેલ છે. |
02.28 | આપણે a ને ફરીથી 1 થી ઈનીશ્યલાઈઝ કરીશું તેથી ફેરફારો પર અસર થાય. |
02.36 | હવે આપણે પ્રિફિક્સ ઇન્ક્રીમેન્ટ ઓપરેટરો વિષે શીખીશું. |
02.39 | આ printf સ્ટેટમેન્ટ સ્ક્રીન ઉપર 2 પ્રિન્ટ કરે છે. |
02.43 | કારણ કે ઓપરેન્ડના મૂલ્યાંકન થાય પછી પ્રીફિક્સ ઓપરેશન થાય છે. |
02.50 | તેથી a ની વેલ્યુ પ્રથમ 1 દ્વારા વધે છે અને પછી તે પ્રિન્ટ થયેલ છે. |
02.59 | આપણે કોઈ ફેરફારો છે કે નહીં તે જોવા માટે a ની વેલ્યુ ફરી પ્રિન્ટ કરી છે. |
03.04 | હવે આ કોડ એકઝીક્યુટ કરી તપાસીએ. |
03.08 | હું નીચેની લીટીઓ કમેન્ટ કરીશ. ટાઇપ કરો / *, * / |
03.19 | Save ઉપર ક્લિક કરો. |
03.23 | મેં મારી ફાઈલ incrdecr.c તરીકે સંગ્રહ કરી છે. |
03.30 | Ctrl, Alt અને T કીઝ એકસાથે દબાવી ટર્મિનલ વિન્ડો ખોલો. |
03.36 | કમ્પાઈલ કરવા માટે, ટર્મિનલ ઉપર નીચે આપેલ ટાઇપ કરો, gcc incrdecr.c -o incr. એન્ટર ડબાઓ. |
03.52 | કોડ એક્ઝીક્યુટ કરવા માટે, ટાઇપ કરો, ./incr'. એન્ટર ડબાઓ. |
03.59 | આઉટપુટ સ્ક્રીન ઉપર દ્રશ્યમાન થાય છે. |
04.02 | તમે a++ પ્રિન્ટ કરો છો ત્યારે આઉટપુટ આ આવે છે. |
04.06 | તમે ++a પ્રિન્ટ કરો છો ત્યારે આઉટપુટ આ આવે છે. |
04.10 | આપણે જોઈ શકીએ છીએ કે પરિણામ પહેલા ચર્ચા કર્યું હતું તે પ્રમાણે છે.
|
04.13 | હવે બાકીના કોડ ઉપર પાછા આવીએ. |
04.17 | હું હવે પોસ્ટફિક્સ અને પ્રિફિક્સ ડીક્રીમેન્ટ ઓપરેટરો સમજાવીશ. |
04.22 | અહીં અને અહીં થી મલ્ટી લાઇન કમેન્ટ રદ કરો.
|
04.29 | આપણે હવે ફરીથી 1 વેલ્યુ ને a માં અસાઇન કરીએ. |
04.36 | printf સ્ટેટમેન્ટ પહેલાં સમજાવ્યા મુજબ 1 ની વેલ્યુ આઉટપુટમાં આપે છે. |
04.42 | a ની વેલ્યુ a-- ના મૂલ્યાંકન પછી ધટશે કારણ કે તે પોસ્ટફિક્સ એક્સપ્રેશન છે. |
04.51 | printf સ્ટેટમેન્ટ પહેલાં સમજાવ્યા મુજબ 1 ની વેલ્યુ આઉટપુટમાં આપે છે. |
04.57 | a ની વેલ્યુ a-- ના મૂલ્યાંકન પછી ૧ દ્વારા ધટશે કારણ કે તે પોસ્ટફિક્સ એક્સપ્રેશન છે. |
05.03 | The next statement prints a's value as o. |
05.07 | A's value has now decremeted being1. |
05.10 | We now have the prefix decrement operator. |
05.14 | Output of this printf statement would be 0. |
05.17 | As it is a prefix operation. |
05.21 | The prefix operation occurs before the operand is evaluated. |
05.25 | This printf statements output is 0. |
05.28 | No further changes have being made to a's value. |
05.31 | Type return 0; And close the ending curly bracket |
05.37 | Click on Save. |
05.40 | Switch back to the terminal. |
05.43 | To compile type the following on the terminal; gcc incrdecr.c -o incr. Press Enter. |
05.58 | To execute type, ./incr.Press Enter.
|
06.08 | This is the output when you print a--
|
06.12 | This is the output when you print --a
|
06.15 | So, now we see how the increment and decrement operator works. |
06.21 | If we want to write the same program in C++. |
06.23 | I can make a few changes to the above C code. |
06.26 | Let me go back to the editor. |
06.29 | Here is the C++ file with the necessary code.
|
06.33 | Notice that the header is different from the C file header. |
06.37 | We have the using namespace statement here. |
06.40 | Also, note that the output statement in C++ is cout. |
06.45 | So, apart from these differences, the two codes are very similar. |
06.49 | Save the file. The file is saved with an extension .cpp |
06.56 | Let's compile the code. |
06.58 | Open the terminal and type g++ incrdecr.cpp -o incr. Press Enter. |
07.16 | To execute Type ./ incr.Press Enter. |
07.23 | The output is displayed on the screen:
|
07.27 | So, we see the output is identical to the C program. |
07.31 | We now have the concept of typecasting. |
07.33 | It is implemented the same way in both C and C++. |
07.38 | Typecasting is a used to make a variable of one type, act like another type. |
07.43 | Typecasting is done by enclosing the data type you want within parenthesis. |
07.49 | This cast is put in front of the variable you want to cast. |
07.54 | This typecast is valid for one single operation only. |
07.58 | Now a will behave as a float variable for a single operation. |
08.03 | Here is an example I have already created. |
08.06 | I shall now explain the code. |
08.11 | We first declare the variables a and b as integer and c as float. |
08.16 | a is assigned the value 5. b is assigned the value 2. |
08.22 | We will perform operations on a and b. |
08.26 | We divide a by b. The result of division is stored in c. |
08.30 | We have used %.2f to denote a precision of 2 decimal places. |
08.35 | The result displayed will be 2.00 against the expected result of 2.50. |
08.41 | The fractional part has been truncated as both the operands a and b are integers. |
08.47 | To perform real division one of the operands will have to be type cast to float. |
08.51 | Here we are typecasting a to float. c now holds the value of real division. |
08.57 | Now the result of real division is displayed. The answer is 2.50 as expected. |
09.03 | Type return 0; and close the ending curly bracket. |
09.07 | Click on Save. Save the file with .c extension. |
09.11 | I have saved my file as typecast.c. |
09.15 | Open the terminal. |
09.17 | To compile, type gcc typecast.c -o type.Press Enter. |
09.33 | to execute, type ./type.Press Enter. |
09.41 | The output is displayed on the screen.
|
09.44 | looking at the two values we see the effects of typecasting. |
09.48 | We will summarize the tutorial now. |
09.50 | In this tutorial we learnt, |
09.52 | How to use the increment and decrement operators. |
09.56 | We learn't about the form Postfix and Prefix
|
10.00 | Also we learnt about typecasting and how it is used. |
10.04 | As an assignment: |
10.05 | Write a program to solve the following expression, (a\b) + (c\d) |
10.12 | The values of a, b, c and d are taken as input from the user. |
10.17 | Use typecasting to perform real division. |
10.21 | Watch the video available at the following link |
10.24 | It summarises the Spoken Tutorial project |
10.27 | If you do not have good bandwidth, you can download and watch it
|
10.321 | The Spoken Tutorial Project Team |
10.34 | Conducts workshops using spoken tutorials |
10.36 | Gives certificates for those who pass an online test |
10.410 | For more details, please write to contact at spoken hyphen tutorial dot org
|
10.49 | Spoken Tutorial Project is a part of the Talk to a Teacher project |
10.53 | It is supported by the National Mission on Education through ICT, MHRD, Government of India |
11.00 | More information on this Mission is available at spoken hyphen tutorial dot org slash NMEICT hyphen Intro
|
11.11 | This is Ritwik Joshi from IIT Bombay.
Thank you for joining. |
Contributors and Content Editors
Ashwini, Devisenan, Jyotisolanki, Krupali, PoojaMoolya, Pratik kamble, Sandhya.np14