C-and-C++/C2/Tokens/English-timed
From Script | Spoken-Tutorial
| Time | Narration |
| 00.01 | Welcome to the spoken tutorial on 'Tokens-in-C-and-C-Plus-Plus |
| 00.06 | In this tutorial we will learn , |
| 00.09 | How to define and use tokens. |
| 00.12 | We will do this with the help of an example. |
| 00.15 | We will also see some common errors and their solutions. |
| 00.20 | To record this tutorial, |
| 00.21 | I am using Ubuntu Operating system version 11.10gcc and g++ Compiler version 4.6.1. |
| 00.33 | Let us start with an introduction |
| 00.37 | Token is a generic word for Data types, Variables, Constants and Identifiers |
| 00.46 | Let us start with our program |
| 00.49 | I have already typed the code on the editor |
| 00.53 | Let me open it. Note that our file name is Tokens .c. |
| 01.04 | In this program we will initialize the variables and print their values . |
| 01.09 | Let me explain the code now. This is our header file. |
| 01.16 | This is our main functions. |
| 01.20 | Here, int is a keyword |
| 01.22 | The compiler knows the meaning of keywords. |
| 01.26 | a is an integer variable |
| 01.29 | We have assigned a value of 2 to it. |
| 01.32 | This is called as initialization. |
| 01.35 | If a value is not assigned to a variable then it is called as declaration of the variable. |
| 01.43 | Here, b is a constant. |
| 01.46 | We have initialized b, by assigning a value of 4 to it. |
| 01.53 | const keyword is used to create read only variable |
| 01.58 | Let us switch back to our slides to know more about keywords and constant. |
| 02.06 | Keywords have fixed meanings that cannot be changed |
| 02.11 | Keywords cannot be used as variable names |
| 02.15 | There are 32 keywords in C |
| 02.18 | To name some, auto, break, case, char, enum extern, etc. |
| 02.28 | Constants, Constants are fixed values. |
| 02.34 | They do not change during the execution of a program. There are two types of constants ,
Numeric constants and Character constants. |
| 02.45 | Now come back to our program. |
| 02.47 | 'Here, float is a data type of variable c. |
| 02.52 | We have assigned it a value of , 1.5 |
| 02.57 | Data type is a finite set of values along with a set of rules |
| 03.05 | Here, d is a variable |
| 03.07 | Char and single quotes suggest that we are dealing with a character |
| 03.13 | As a result, d is a character variable storing the value 'A' |
| 03.20 | It is easy to see that int, double float and char are datatypes. |
| 03.30 | a, c and d are variables |
| 03.36 | Now come back to our slides. |
| 03.38 | We will know more about datatypes and variable |
| 03.48 | Let us begin with integer data type |
| 03.51 | It is declared as int |
| 03.53 | If we want to print an integer data type , we will use %d as the format specifier |
| 04.01 | Similarly, we will use float and %f for floating point numbers |
| 04.09 | For character data type, we will use char and %c |
| 04.15 | And For double data type, we use double and %lf as the format specifier. |
| 04.25 | Now we will see the range of data types |
| 04.29 | Integerdata type has a range of this -32,768 to 32,767 |
| 04.34 | Floating point has a range of this 3.4E +/-38 |
| 04.39 | Character has a range of this -128 to 127 |
| 04.42 | And Double has a range of this 1.7E +/-308 |
| 04.48 | The values stored in the variable must not be greater or less than this range. |
| 04.56 | Now we will move on to variables. |
| 05.00 | Variable is a data name. |
| 05.03 | It may be used to store a data value . |
| 05.06 | The values can change when a program runs. |
| 05.10 | Before using a variable it must be declared |
| 05.15 | We should try to give meaningful names to variables |
| 05.19 | example john, marks, sum etc. |
| 05.24 | Now move back to our program. |
| 05.27 | Here, printf is the identifier name for this function
|
| 05.32 | Come back to our slides. Let us know about identifiers. |
| 05.38 | Identifiers are user defined names |
| 05.41 | An identifier consists of letters and digits |
| 05.46 | Both uppercase and lowercase letters are permitted |
| 05.51 | First character must be an alphabet or underscore . |
| 05.55 | Now Come back to our program |
| 05.58 | Here we have initialized the variables and constants. Here we print them. |
| 06.05 | And this is our return statement. Now click on save. |
| 06.10 | Let us execute the program |
| 06.12 | Please open the terminal window by pressing Ctrl, Alt and T keys simultaneously on your keyboard. |
| 06.21 | To compile ,Type gcc tokens.c -o tok press Enter |
| 06.30 | To execute type./tok |
| 06.35 | The output is displayed. |
| 06.39 | We can see that here we have six values after the decimal point. |
| 06.44 | And here we have two values. |
| 06.48 | Now let us find out how this happened. Come back to our program. |
| 06.54 | This is because we have %.2f here. |
| 06.59 | It denotes that we can print only two values after the decimal point.
|
| 07.04 | here I want an output with three decimal places. |
| 07.09 | Let us replace %.2f with %.3f |
| 07.16 | Now Click on Save |
| 07.20 | Come back to the terminal. compile as before, execute as before. |
| 07.29 | We can see here three values after the decimal point. |
| 07.33 | NOW WE WILL EXECUTE THE SAME PROGRAM IN C++
|
| 07.37 | Come back to our program |
| 07.40 | I will change a few things here |
| 07.42 | First press shift+ctrl+s keys simultaneously on your keyboard. |
| 07.50 | Now save the file with an extension .cpp and click on save |
| 07.58 | let us change the header file as iostream |
| 08.03 | Now include the using statement And click on Save. |
| 08.11 | Now replace the printf statement with the cout statement |
| 08.15 | Since we use cout<< function' to print a line in C++ |
| 08.21 | Click on Search for and replace text option |
| 08.28 | Type here printf opening bracket “(” |
| 08.33 | And here in this column type, |
| 08.35 | cout and two opening angle brackets “<<”. Now click on Replace All and click on Close. |
| 08.45 | We don't need the format specifier /n |
| 08.50 | Let us delete them.Now delete the comma. |
| 08.54 | And type two opening angle brackets. |
| 09.01 | Click on Save. Now delete the closing bracket
|
| 09.06 | Type two opening angle brackets again.
|
| 09.09 | And within the double quotes type \n. Now Click on Save |
| 09.20 | Let us execute the program.Come back to the terminal. |
| 09.24 | To compile , type g++ tokens.cpp -o tok 1
|
| 09.35 | Here we have tok1 |
| 09.36 | Because we don't want to overwrite the output parameter tok for the file tokens.c . Now press Enter |
| 09.48 | To execute.Type ./tok1 . press Enter |
| 09.55 | The output is displayed.
|
| 09.59 | Now let us move on to some common errors which we can come across. |
| 10.03 | Come back to our program.Suppose here I will reassign a new value to b as 8. |
| 10.13 | now Click on Save. Let us see what happens. |
| 10.15 | Come back to our terminal.Let me clear the prompt. |
| 10.22 | Now compile as before. |
| 10.26 | We see an error at line no.7 in our tokens. cpp file. |
| 10.32 | Assignment of read only variable b. |
| 10.36 | Come back to our program |
| 10.40 | This is because b is a constant. Constants are fixed values. |
| 10.46 | They do not change during the execution of program. |
| 10.49 | Hence it is giving an error.Let us fix the error. |
| 10.54 | Delete this. Click on Save |
| 10.57 | Let us execute again. Come back to our terminal |
| 11.01 | Compile as before.Execute as before.Yes it is working. |
| 11.09 | Now we will see another common error. |
| 11.12 | Switch back to our program. |
| 11.15 | Suppose here I will miss the single quotes. Click on Save |
| 11.21 | let us execute.Come back to our terminal. |
| 11.25 | Compile as before. |
| 11.28 | we see an error at line no.9 in our tokens. cpp file. |
| 11.34 | A was not declared in the scope. Come back to our program. |
| 11.40 | This is because anything within the single quotes is considered as a character value. |
| 11.47 | And here we have declared d as a character variable. |
| 11.53 | Let us fix the error. Type single quotes at line no.9 here. |
| 11.59 | Now Click on Save . Let us execute . |
| 12.02 | Come back to our terminal |
| 12.04 | Now Compile as before |
| 12.06 | Execute as before. Yes it is working. |
| 12.14 | Now switch back to our slides. |
| 12.15 | Let us summarize |
| 12.16 | In this tutorial we learnt, |
| 12.18 | Data types eg. int, double, float etc. |
| 12.24 | Variables eg. int a=2; |
| 12.29 | Identifiers eg. printf() and |
| 12.34 | Constant eg. double const b=4; |
| 12.40 | As an assignment |
| 12.41 | Write a C program to calculate the simple interest. |
| 12.45 | Hint: Simple Interest = principal * rate * time / 100 |
| 12.51 | Watch the video available at http://spoken-tutorial.org /What\_is\_a\_Spoken\_Tutorial |
| 12.54 | It summarises the Spoken Tutorial project |
| 12.57 | If you do not have good bandwidth, you can download and watch it. |
| 13.01 | The Spoken Tutorial Project Team |
| 13.03 | Conducts workshops using spoken tutorials |
| 13.07 | Gives certificates to those who pass an online test |
| 13.11 | For more details,please write to contact @spoken-tutorial.org |
| 13.20 | Spoken Tutorial Project is a part of the Talk to a Teacher project |
| 13.24 | It is supported by the National Mission on Education through ICT, MHRD, Government of India |
| 13.30 | More information on this Mission is available at: http://spoken-tutorial.org\NMEICT-Intro |
| 13.35 | Ashwini Patil from IIT BombayThank You for joining |
Contributors and Content Editors
Jyotisolanki, Krupali, PoojaMoolya, Pratik kamble, Sandhya.np14, Sneha