Difference between revisions of "C-and-C++/C4/Understanding-Pointers/English-timed"
From Script | Spoken-Tutorial
PoojaMoolya (Talk | contribs) |
|||
Line 1: | Line 1: | ||
− | {| border=1 | + | {| border = 1 |
− | + | ||
− | + | |'''Time''' | |
+ | |||
+ | |'''Narration''' | ||
+ | |||
|- | |- | ||
− | | 00 | + | | 00.01 |
− | |Welcome to the spoken tutorial on Pointers in C and C++ | + | |Welcome to the spoken tutorial on Pointers in C and C++ |
|- | |- | ||
− | | 00 | + | | 00.06 |
− | |In this tutorial we will learn | + | |In this tutorial we will learn, |
|- | |- | ||
− | | 00 | + | | 00.08 |
− | | Pointers. | + | |Pointers. |
|- | |- | ||
− | | 00 | + | | 00.10 |
− | | To create Pointers. | + | |To create Pointers. |
|- | |- | ||
− | | 00 | + | | 00.12 |
− | |And operations on | + | |And operations on Pointers. |
|- | |- | ||
− | | 00 | + | | 00.14 |
− | |We will do this with the help of an example | + | | We will do this with the help of an example |
|- | |- | ||
− | | 00 | + | | 00.18 |
− | | To record this tutorial I am using | + | |To record this tutorial I am using Ubuntu operating system version 11.10 |
− | + | ||
− | Ubuntu | + | |
− | + | ||
− | + | ||
+ | |- | ||
+ | | 00.25 | ||
+ | | gcc and g++ compiler version 4.6.1 on Ubuntu | ||
|- | |- | ||
− | | 00 | + | | 00.31 |
− | |Let us start with | + | |Let us start with an introduction to pointers |
|- | |- | ||
− | | 00 | + | |00.34 |
− | | Pointers point to the locations in memory. | + | |Pointers point to the locations in memory. |
− | |||
|- | |- | ||
− | | 00 | + | |00.38 |
− | |Pointers store | + | |Pointers store the memory address. |
− | + | ||
|- | |- | ||
− | | 00 | + | | 00.41 |
− | |It also gives value stored at that address. | + | |It also gives value stored at that address. |
|- | |- | ||
− | | | + | | 00.45 |
− | | Now let us | + | |Now, let us see an example on pointers |
|- | |- | ||
− | | 00 | + | | 00.48 |
− | | Note that our file name is | + | |Note that our file name is pointers_demo.c |
− | + | ||
− | + | ||
|- | |- | ||
− | | 00 | + | | 00.54 |
|Let us go through the code now | |Let us go through the code now | ||
+ | |||
|- | |- | ||
− | | 00 | + | | 00.56 |
− | |This is our | + | |This is our header file as stdio.h |
+ | |||
|- | |- | ||
− | | 01 | + | | 01.00 |
− | |This is our main function | + | |This is our main function |
+ | |||
|- | |- | ||
− | | 01 | + | | 01.03 |
− | |Here we have long integer | + | |Here we have long integer num assigned value 10. |
− | + | ||
|- | |- | ||
− | | | + | | 01.09 |
− | | Then we have declared a pointer | + | |Then we have declared a pointer ptr. |
|- | |- | ||
− | | 01 | + | | 01.12 |
− | | | + | |Asterisk sign is used to declare a pointer. |
|- | |- | ||
− | | 01 | + | | 01.16 |
− | |This pointer can point to type long int. | + | |This pointer can point to type long int. |
|- | |- | ||
− | | | + | | 01.20 |
− | |In the printf | + | |In the printf statement ampersand is used for retrieving memory address of the variable. |
|- | |- | ||
− | | 01 | + | |01.28 |
− | |So ampersand num will give the memory address of num. | + | |So ampersand num will give the memory address of num. |
|- | |- | ||
− | | 01 | + | | 01.33 |
− | |This statement will print the address of the variable num. | + | |This statement will print the address of the variable num. |
|- | |- | ||
− | | | + | | 01.37 |
− | | | + | |Over here ptr stores the address of num. |
|- | |- | ||
− | | | + | | 01.41 |
− | | | + | |This statement will print the address of ptr. |
+ | |||
|- | |- | ||
− | | | + | | 01.45 |
− | | Size of function will give the size of ptr. | + | |Size of function will give the size of ptr. |
|- | |- | ||
− | | 01 | + | |01.49 |
− | | | + | |This is will give the value of ptr. |
|- | |- | ||
− | | 01 | + | |01.51 |
− | |That is the memory address of num. | + | |That is the memory address of num. |
|- | |- | ||
− | | 01 | + | |01.54 |
− | | | + | |And here asterisk ptr will give the value at the address. |
− | + | ||
|- | |- | ||
− | | | + | |01.59 |
− | |So using | + | |So using asterik will not give the memory address. |
|- | |- | ||
− | | 02 | + | |02.03 |
− | |Instead it will give the value | + | |Instead it will give the value. |
|- | |- | ||
− | | | + | |02.06 |
− | | | + | |%ld is a format specifier for the long int |
+ | |||
|- | |- | ||
− | | | + | |02.10 |
− | | | + | |Now, let us execute the program |
|- | |- | ||
− | | | + | |02.13 |
− | | | + | |Open the terinal window by pressing Ctrl, Alt and T keys simultaneously on your keyboard |
+ | |||
|- | |- | ||
− | | 02 | + | |02.21 |
− | |gcc | + | |To compile type gcc space pointers underscore demo dot c space hyphen o space point |
+ | |||
+ | |||
|- | |- | ||
− | | 02 | + | |02.32 |
|Press Enter | |Press Enter | ||
+ | |||
|- | |- | ||
− | | 02 | + | |02.34 |
− | | | + | |Type dot slash point. Press Enter |
+ | |||
|- | |- | ||
− | | 02 | + | |02.39 |
|The output is displayed | |The output is displayed | ||
+ | |||
|- | |- | ||
− | | 02 | + | | 02.42 |
− | |We see that the num address and ptr value is same. | + | |We see that the num address and ptr value is same. |
+ | |||
|- | |- | ||
− | | 02 | + | | 02.48 |
− | | | + | | Where as memory address of num and ptr are different. |
+ | |||
|- | |- | ||
− | | 02 | + | | 02.53 |
− | |Then the size of pointer is 8 bytes. | + | |Then the size of pointer is 8 bytes. |
+ | |||
|- | |- | ||
− | | 02 | + | | 02.57 |
− | |Also the value pointed by ptr is 10 which was assigned to num | + | | Also the value pointed by ptr is 10 which was assigned to num. |
|- | |- | ||
− | | 03 | + | | 03.03 |
− | |Now let us see the same program in C++. | + | | Now let us see the same program in C++. |
|- | |- | ||
− | | 03 | + | | 03.07 |
− | |Note that our | + | | Note that our file name is pointer underscore demo.cpp |
|- | |- | ||
− | | 03 | + | | 03.13 |
− | |Here we have | + | | Here we have few changes like the header file as iostream |
− | + | ||
|- | |- | ||
− | | | + | | 03.19 |
− | | | + | |Then we are using the std namespace |
|- | |- | ||
− | | 03 | + | | 03.23 |
− | |And | + | |And we have the cout function in place of printf function |
+ | |- | ||
+ | | 03.28 | ||
+ | |Rest all the things are similar | ||
|- | |- | ||
− | | | + | | 03.30 |
− | | | + | |Let us execute the program. Come back to our terminal. |
|- | |- | ||
− | | 03 | + | | 03.34 |
− | | | + | |To compile type g++ space pointers_demo.cpp space hyphen o space point1, press Enter |
+ | |||
|- | |- | ||
− | | 03 | + | | 03.50 |
− | | | + | |Type dot slash point1, press Enter |
+ | |||
|- | |- | ||
− | | 03 | + | | 03.55 |
− | + | | We can see that the output is similar to our C program | |
− | + | ||
− | + | ||
− | + | ||
− | | | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
− | + | | 04.00 | |
− | + | ||
− | + | ||
− | | 04 | + | |
|This brings us to the end of this tutorial. | |This brings us to the end of this tutorial. | ||
+ | |||
|- | |- | ||
− | | 04 | + | | 04.03 |
− | |Come back to our | + | | Come back to our slide |
+ | |||
|- | |- | ||
− | | 04 | + | | 04.05 |
− | | Let us summarize | + | |Let us summarize |
+ | |||
|- | |- | ||
− | | 04 | + | | 04.06 |
− | | In this tutorial we | + | |In this tutorial, we learnt |
+ | |||
|- | |- | ||
− | | 04 | + | | 04.08 |
− | | About the pointer. | + | |About the pointer. |
+ | |||
|- | |- | ||
− | | 04 | + | | 04.10 |
− | | To create a pointer. | + | |To create a pointer. |
+ | |||
|- | |- | ||
− | | 04 | + | | 04.12 |
− | | And | + | |And operation on pointer. |
|- | |- | ||
− | | 04 | + | | 04.14 |
− | |As an assignment write a C and C++ program, | + | |As an assignment, write a C and C++ program, |
− | + | ||
|- | |- | ||
− | | 04 | + | | 04.18 |
− | |To declare a variable and pointer. | + | |To declare a variable and pointer. |
|- | |- | ||
− | | 04 | + | | 04.21 |
− | |Store the address of variable in the pointer. | + | | Store the address of variable in the pointer. |
|- | |- | ||
− | | 04 | + | | 04.24 |
− | |And | + | |And print the value of the pointer. |
− | |||
|- | |- | ||
− | | 04 | + | | 04.27 |
− | | Watch the video available at | + | |Watch the video available at the link shown below |
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
− | | 04 | + | | 04.30 |
− | | | + | |It summarizes the Spoken Tutorial project |
− | + | ||
− | + | ||
|- | |- | ||
− | | | + | | 04.33 |
− | | | + | |If you do not have good bandwidth, you can download and watch it |
|- | |- | ||
− | | 04 | + | | 04.37 |
− | | | + | |The Spoken Tutorial Project Team |
|- | |- | ||
− | | 04 | + | | 04.39 |
− | | | + | |Conducts workshops using spoken tutorials |
+ | |- | ||
+ | |04.43 | ||
+ | |Gives certificates to those who pass an online test | ||
|- | |- | ||
− | | 04 | + | | 04.47 |
− | | For more details, please write to contact@spoken-tutorial.org | + | |For more details, please write to, contact@spoken-tutorial.org |
− | + | ||
− | + | ||
|- | |- | ||
− | | | + | | 04.53 |
− | | 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 |
|- | |- | ||
− | | 04 | + | | 04.58 |
− | |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 |
|- | |- | ||
− | |05 | + | | 05.06 |
− | | More information on this Mission is available at | + | |More information on this Mission is available at the link shown below |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
− | | 05 | + | | 05.10 |
− | | This is Ashwini Patil from IIT | + | | This is Ashwini Patil from IIT Bombay signing off |
|- | |- | ||
− | | 05 | + | | 05.14 |
− | | | + | |Thank You for joining. |
Revision as of 16:25, 22 November 2013
Time | Narration
|
00.01 | Welcome to the spoken tutorial on Pointers in C and C++ |
00.06 | In this tutorial we will learn, |
00.08 | Pointers. |
00.10 | To create Pointers. |
00.12 | And operations on Pointers. |
00.14 | We will do this with the help of an example |
00.18 | To record this tutorial I am using Ubuntu operating system version 11.10 |
00.25 | gcc and g++ compiler version 4.6.1 on Ubuntu |
00.31 | Let us start with an introduction to pointers |
00.34 | Pointers point to the locations in memory. |
00.38 | Pointers store the memory address. |
00.41 | It also gives value stored at that address. |
00.45 | Now, let us see an example on pointers |
00.48 | Note that our file name is pointers_demo.c |
00.54 | Let us go through the code now |
00.56 | This is our header file as stdio.h |
01.00 | This is our main function |
01.03 | Here we have long integer num assigned value 10. |
01.09 | Then we have declared a pointer ptr. |
01.12 | Asterisk sign is used to declare a pointer. |
01.16 | This pointer can point to type long int. |
01.20 | In the printf statement ampersand is used for retrieving memory address of the variable. |
01.28 | So ampersand num will give the memory address of num. |
01.33 | This statement will print the address of the variable num. |
01.37 | Over here ptr stores the address of num. |
01.41 | This statement will print the address of ptr.
|
01.45 | Size of function will give the size of ptr. |
01.49 | This is will give the value of ptr. |
01.51 | That is the memory address of num. |
01.54 | And here asterisk ptr will give the value at the address. |
01.59 | So using asterik will not give the memory address. |
02.03 | Instead it will give the value. |
02.06 | %ld is a format specifier for the long int |
02.10 | Now, let us execute the program |
02.13 | Open the terinal window by pressing Ctrl, Alt and T keys simultaneously on your keyboard |
02.21 | To compile type gcc space pointers underscore demo dot c space hyphen o space point
|
02.32 | Press Enter |
02.34 | Type dot slash point. Press Enter |
02.39 | The output is displayed |
02.42 | We see that the num address and ptr value is same. |
02.48 | Where as memory address of num and ptr are different. |
02.53 | Then the size of pointer is 8 bytes. |
02.57 | Also the value pointed by ptr is 10 which was assigned to num. |
03.03 | Now let us see the same program in C++. |
03.07 | Note that our file name is pointer underscore demo.cpp |
03.13 | Here we have few changes like the header file as iostream |
03.19 | Then we are using the std namespace |
03.23 | And we have the cout function in place of printf function |
03.28 | Rest all the things are similar |
03.30 | Let us execute the program. Come back to our terminal. |
03.34 | To compile type g++ space pointers_demo.cpp space hyphen o space point1, press Enter |
03.50 | Type dot slash point1, press Enter |
03.55 | We can see that the output is similar to our C program |
04.00 | This brings us to the end of this tutorial. |
04.03 | Come back to our slide |
04.05 | Let us summarize |
04.06 | In this tutorial, we learnt |
04.08 | About the pointer. |
04.10 | To create a pointer. |
04.12 | And operation on pointer. |
04.14 | As an assignment, write a C and C++ program, |
04.18 | To declare a variable and pointer. |
04.21 | Store the address of variable in the pointer. |
04.24 | And print the value of the pointer. |
04.27 | Watch the video available at the link shown below |
04.30 | It summarizes the Spoken Tutorial project |
04.33 | If you do not have good bandwidth, you can download and watch it |
04.37 | The Spoken Tutorial Project Team |
04.39 | Conducts workshops using spoken tutorials |
04.43 | Gives certificates to those who pass an online test |
04.47 | For more details, please write to, contact@spoken-tutorial.org |
04.53 | Spoken Tutorial Project is a part of the Talk to a Teacher project |
04.58 | It is supported by the National Mission on Education through ICT, MHRD, Government of India |
05.06 | More information on this Mission is available at the link shown below |
05.10 | This is Ashwini Patil from IIT Bombay signing off |
05.14 | Thank You for joining. |
Contributors and Content Editors
Kavita salve, Krupali, PoojaMoolya, Pratik kamble, Sandhya.np14, Sneha