Difference between revisions of "C-and-C++/C4/Understanding-Pointers/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with ''''Title of script''': Pointer in C and C++ '''Author: Ashwini Patil''' '''Keywords: Pointers, video tutorial()''' {| style="border-spacing:0;" | style="border-top:0.002cm s…')
 
 
(2 intermediate revisions by the same user not shown)
Line 13: Line 13:
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Opening slide1
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Opening slide1
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Welcome to the spoken tutorial on Pointers in C and C++
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Welcome to the spoken tutorial on '''Pointers in C and C++'''
  
 
|-
 
|-
Line 19: Line 19:
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| In this tutorial we will learn
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| In this tutorial we will learn
  
What are Pointers.
+
Pointers.
  
How to create Pointers.
+
To create Pointers.
  
 
And operations on Pointer.
 
And operations on Pointer.
 +
 +
We will do this with the help of an example.
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| System Requirement Slide 3
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| System Requirement Slide 3
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| For this tutorial I am using  
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| To record this tutorial I am using  
  
Ubuntu 11.10 OS
+
Ubuntu OS version11.10  
  
gcc compiler and g++
+
gcc and g++ compiler version 4.6.1 on Ubuntu
 
+
|-
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Prerequisites
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| To follow this tutorial you must know how to write and run a C and C++ program.
+
 
+
 
+
If not, for relevant tutorials please visit our website as shown.
+
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| What is a Pointer?
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| What is a Pointer?
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Pointers point to the locations in memory.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Let is start with an introduction to pointers.
 
+
Pointers point to the locations in memory.
  
 
Pointers store the memory address.  
 
Pointers store the memory address.  
 
  
 
It also gives value stored at that address.
 
It also gives value stored at that address.
Line 53: Line 47:
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Switch to gedit Text Editor
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Switch to gedit Text Editor
  
 +
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"|Now let us see an example on Pointers
 +
Note that our filename is '''pointers_demo.c'''
 +
Let us go through the code now.
  
Highlight num
+
This is our header file as '''stdio.h'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Let us now see the code
+
  
 +
This is our main function.
 +
 +
|-
 +
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"|
 +
Highlight num
  
We have a variable num assigned value 10.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"|
 +
Here we have a '''long integer num''' assigned value '''10.'''
  
 
|-
 
|-
Line 66: Line 68:
 
Asterisk sign is used to declare a pointer.
 
Asterisk sign is used to declare a pointer.
  
This pointer can point to type int.
+
This pointer can point to type '''long int.'''
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight &num
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight &num
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Ampersand is used for retrieving memory address of the variable.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| In the printf statement ampersand is used for retrieving memory address of the variable.
  
So ampersand num will give the memory laddress of num.
+
So ampersand num will give the memory address of num.
  
 
This statement will print the address of the variable num.
 
This statement will print the address of the variable num.
Line 90: Line 92:
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight ptr
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight ptr
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| This is will give the value of ptr.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| This will give the value of ptr.
  
 
That is the memory address of num.
 
That is the memory address of num.
Line 96: Line 98:
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight *ptr
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight *ptr
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| And asterisk ptr will give the value at the address.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| And here asterisk ptr will give the value at the address.
  
 
So using asterik will not give the memory address.
 
So using asterik will not give the memory address.
  
 
Instead it will give the value.
 
Instead it will give the value.
 +
 +
%ld is the format specifier for long int.
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Save, Compile and Run
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Save, Compile and Run
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Save , Compile and Run the file.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"|Now let us execute the program.
 +
Open the '''terminal''' by pressing '''Ctrl, Alt and T''' keys simultaneously on your keyboard.
  
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Output
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Type: gcc pointers_demo.c -o point.
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| We see the output that num address and ptr value is same.
+
./point
 +
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| To compile type:
 +
gcc space pointers_demo.c space -o space point.
 +
'''Press Enter'''
 +
./point
 +
'''Press Enter'''
  
Where as memory address of num and ptr are different.
 
 
Then the size of pointer is 4 bytes.
 
 
Since int type size is 4 bytes.
 
 
Also the value pointed by ptr is 10 which was assigned to num.
 
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Code in C++
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Now let us see the same code in C++.
 
 
It is similar to C.
 
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Save, Compile and Run
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Save, compile and Run the file.
 
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Output
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Output
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| We see the same output.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| The output is displayed.
 +
We see that the num address and ptr value is same.
  
So this is how pointers declared and initialized in C and C++.
+
Where as memory address of num and ptr are different.
  
|-
+
Then the size of pointer is '''8 bytes.'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Code in C
+
  
 
+
Also the value pointed by '''ptr''' is 10, which was assigned to '''num.'''
<nowiki>Point to Arr[5]</nowiki>
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| We will now see a opearation perfomed on a pointer.
+
 
+
 
+
In the code, we have declared an array Arr having 5 elements.
+
  
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight *point
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Code in C++
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Then we have declared a pointer point of type int.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Now let us see the same program in C++.
 +
Note that the filename is '''pointers_demo.cpp'''
  
As we see the asterisk sign a the start .
+
Here we have a few changes.
  
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight point = Arr;
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"|Highlight Code in C++
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Then we have assigned the memory address of array to the pointer.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Like the header file as '''iostream'''
 +
Then we are using the '''std namespace'''
  
So point will hold the address of array Arr.
 
  
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight print statement
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"|Highlight Code in C++
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Then we print the address of the pointer holding the first value of array.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Here we have cout function in place of printf function.
 +
Rest all the things are similar.
  
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight point++
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Here ++ operator moves the pointer ahead by one memory address.
 
 
So now it will point to the second value of array that it holds.
 
  
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight print statement
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| On the terminal
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| This will print the address and value that pointer point is currently holding.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"|Let us execute the program.
 +
Come back to our terminal.
  
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight point++
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"|  
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Again point++.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"|To compile type:
  
So again it will point to the next memory address.
+
'''g++ space pointers_demo.cpp space -o space point1'''
  
That is to the 3<sup>rd</sup> value of array.
+
'''Press Enter'''
  
Similarly – operator will make pointer point to the previous address.
+
Type
  
|-
+
./point1
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight %p %d
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Here make a note.
+
  
Percent p is used as format specifiers for pointer.
+
'''Press Enter'''
 
+
While %d for value pointed by the pointer.
+
 
+
This is because value is type int.
+
 
+
|-
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Save, Compile and Run
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Save , Compile and Run the file.
+
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Output
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Output
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| We see the output with addresses and their corresponding values.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| We can see that the output is similar to our C program.
 
+
This brings us to the end of this tutorial.
|-
+
Come back to our slides.
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Code in C++
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| We will see the same code in C++
+
 
+
It looks similar to C.
+
 
+
|-
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Save, Run and Compile
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Save, Run and Compile the program.
+
 
+
|-
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Output
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| We see the same output.
+
 
+
So this is how pointers can be used in C and C++.
+
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Summary Slide
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Summary Slide
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| So in this tutorial we have learnt.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Let us summarize.
 +
In this tutorial we have learnt.
  
 
About the pointer.
 
About the pointer.
Line 226: Line 189:
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Assignment Slide
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Assignment Slide
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| For self assessment write a C and C++ program,
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| As an assignment
 +
Write a C and C++ program,
  
 
declare a variable and pointer.
 
declare a variable and pointer.
Line 239: Line 203:
 
About Slide
 
About Slide
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| To know more about the Spoken Tutorial Project
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| To know more about the Spoken Tutorial Project
* Watch the video available at [http://spoken-tutorial.org/What_is_a_Spoken_Tutorial http://spoken-][http://spoken-tutorial.org/What_is_a_Spoken_Tutorial tutorial.org/What_is_a_Spoken_Tutorial]  
+
* Watch the video available at the link shown below[http://spoken-tutorial.org/What_is_a_Spoken_Tutorial http://spoken-][http://spoken-tutorial.org/What_is_a_Spoken_Tutorial tutorial.org/What_is_a_Spoken_Tutorial]  
 
* It summarizes the Spoken Tutorial project  
 
* It summarizes the Spoken Tutorial project  
  
Line 271: Line 235:
 
* 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  
  
* More information on this Mission is available at  
+
* More information on this Mission is available at the link shown below.
  
 
* [http://spoken-tutorial.org/NMEICT-Intro http://spoken-tutorial.org/NMEICT-Intro]  
 
* [http://spoken-tutorial.org/NMEICT-Intro http://spoken-tutorial.org/NMEICT-Intro]  

Latest revision as of 16:25, 31 January 2014

Title of script: Pointer in C and C++

Author: Ashwini Patil

Keywords: Pointers, video tutorial()


Visual Cue
Narration
Opening slide1 Welcome to the spoken tutorial on Pointers in C and C++
Learning objectives Slide 2 In this tutorial we will learn

Pointers.

To create Pointers.

And operations on Pointer.

We will do this with the help of an example.

System Requirement Slide 3 To record this tutorial I am using

Ubuntu OS version11.10

gcc and g++ compiler version 4.6.1 on Ubuntu

What is a Pointer? Let is start with an introduction to pointers.

Pointers point to the locations in memory.

Pointers store the memory address.

It also gives value stored at that address.

Switch to gedit Text Editor Now let us see an example on Pointers

Note that our filename is pointers_demo.c Let us go through the code now.

This is our header file as stdio.h

This is our main function.

Highlight num

Here we have a long integer num assigned value 10.

Highlight *ptr Then we have declared a pointer ptr.

Asterisk sign is used to declare a pointer.

This pointer can point to type long int.

Highlight &num In the printf statement ampersand is used for retrieving memory address of the variable.

So ampersand num will give the memory address of num.

This statement will print the address of the variable num.

Highlight ptr=&num Over here ptr stores the address of num.
Highlight &ptr This statement will print the address of ptr.
Highlight sizeof(ptr) Sizeof function will give the size of ptr.
Highlight ptr This will give the value of ptr.

That is the memory address of num.

Highlight *ptr And here asterisk ptr will give the value at the address.

So using asterik will not give the memory address.

Instead it will give the value.

%ld is the format specifier for long int.

Save, Compile and Run Now let us execute the program.

Open the terminal by pressing Ctrl, Alt and T keys simultaneously on your keyboard.

Type: gcc pointers_demo.c -o point.

./point

To compile type:

gcc space pointers_demo.c space -o space point. Press Enter ./point Press Enter


Output The output is displayed.

We see that the num address and ptr value is same.

Where as memory address of num and ptr are different.

Then the size of pointer is 8 bytes.

Also the value pointed by ptr is 10, which was assigned to num.

Code in C++ Now let us see the same program in C++.

Note that the filename is pointers_demo.cpp

Here we have a few changes.

Highlight Code in C++ Like the header file as iostream

Then we are using the std namespace


Highlight Code in C++ Here we have cout function in place of printf function.

Rest all the things are similar.


On the terminal Let us execute the program.

Come back to our terminal.

To compile type:

g++ space pointers_demo.cpp space -o space point1

Press Enter

Type

./point1

Press Enter

Output We can see that the output is similar to our C program.

This brings us to the end of this tutorial. Come back to our slides.

Summary Slide Let us summarize.

In this tutorial we have learnt.

About the pointer.

To create a pointer.

Operation on pointer.

Assignment Slide As an assignment

Write a C and C++ program,

declare a variable and pointer.

Store the address of variable in the pointer.

Print the value of pointer.

Slide 8

About Slide

To know more about the Spoken Tutorial Project
  • If you do not have good bandwidth, you can download and watch it


Slide 9

About Slide


The Spoken Tutorial Project Team
  • Conducts workshops using spoken tutorials
  • Gives certificates for those who pass an online test
  • For more details, please write to contact@spoken-tutorial.org


Slide 10

Acknowledgment

Spoken Tutorial Project is a part of the Talk to a Teacher project
  • It is supported by the National Mission on Education through ICT, MHRD, Government of India
  • More information on this Mission is available at the link shown below.


We have come to the end of this tutorial.

Thanks for joining.

This is Ritwik signing off.

Jai Hind.

Contributors and Content Editors

Ashwini