Reference and Pointer ( Lecture 10)
HTML-код
- Опубликовано: 20 дек 2024
- To access the translated content:
1. The translated content of this course is available in regional languages. For details please visit nptel.ac.in/tr...
The video course content can be accessed in the form of regional language text transcripts, books which can be accessed under downloads of each course, subtitles in the video and Video Text Track below the video.
Your feedback is highly appreciated. Kindly fill this form forms.gle/XFZh...
2. Regional language subtitles available for this course
To watch the subtitles in regional languages:
1. Click on the lecture under Course Details.
2. Play the video.
3. Now click on the Settings icon and a list of features will display
4. From that select the option Subtitles/CC.
5. Now select the Language from the available languages to read the subtitle in the regional language.
Sir!! As X+1 is same as ++x ..how it is correct to return(x+1)...it is also a change being made to reference parameter. Please explain sir
x+1 is not same as ++x. x+1 does not increase the x itself but ++x does change the x's value
++x is equivalent to x = (x+1); which is an assignment statement, whereas (x+1) is simply an expression and doesn't affect any variable's existing value
Sir !! Which software I need to use for compilation. Please suggest because I am facing some problems
very nice thanks a lot sir
Sir, I got two doubt from this lecture :
1. int a=10;
int &b = a;
If we print b we will get address of a.
Now if i increment a value of a will increment.
Then if i increment b means ++b or (b+1) then value of b means address of a variable should increment.
how value of a is increment?
2. If i use reference in function call then actual and formal both variable will update. if i dont want to change actual parameter then we can use call by value like C.
Why const reference is required?
1. because a and b point to the same memory location, so any update in either of the variable will be reflected in the other variable. So if you increment b, the value at address pointed by b(as well as a) will be incremented, hence a will also refer to the same incremented value.
2. We still use it so that we can avoid the copy operation (copy of values from actual parameters to formal parameters) which can be compute heavy if the parameters are of complex types like struct.