Pointers / Pointers in the Real World
Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.
Learn More
Subtitles of the Movie
Everything you need to know about pointers has been mentioned in previous lessons but some of the conventional things you can do with pointers are not obvious from such rigorous definitions. You can use an ampersand to get the address of something. Another name for the address of a variable is the Lvalue of the variable. The ampersand produces the Lvalue even though it's on the right-hand side of the assignment. In this example, the pointer named B Pointer is given the address of the variable named barg. If barg is an Array, you don't use the ampersand. The value of the name of an Array is the Lvalue; the address of the first element of that Array. With the pointer initialized this way, you can use it in an expression just like you would use the name of the Array. However, if you want the pointer to address a member of the Array other than the first one, you will need to use a Subscript and an ampersand. Without the ampersand, the expression would result in the Rvalue; the contents of one member of the Array instead of the Lvalue of that member of the Array. With the pointer initialized this way, you can positive index values to address members further along the Array and you can use a negative index value to address members before the one pointed to. If the members of an Array are structs, the addressing is done slightly differently. You can assign a value to the pointer to an Array the same ways as you can a pointer to any Array. Just use the bare Array name to get the Rvalue. But you can't use the two names in exactly the same way in all cases. To address a member of the struct by the name of the Array, use a period as a reference. But to address the member through a pointer, you need to use the arrow construct, which indicates that this is a reference through a pointer. Here's the odd part. If you get it wrong, arrow or period, the compiler will notice and generate an error message. This is one of those things steeped in antiquity in C. Since the compiler always knows the difference, the language could have been designed to be consistent and use a period throughout. But it doesn't. OK, one more. You know that C functions are called by value, by default, but you can define a function to require call by reference. You only want to do this if you want to be able to change the value of an argument inside the function and have that change take place in the variable of the caller. You declare the argument as being a pointer. Then you call it with the Lvalue. You can do that by using a pointer or, as in this example, use the ampersand operator which always returns the address of a variable.
Tutorial Information
| Course: | Advanced C Programming |
| Author: | Arthur Griffith |
| SKU: | 33965 |
| ISBN: | 1-935320-24-6 |
| Release Date: | 2009-01-30 |
| Duration: | 5.5 hrs / 82 lessons |
| Work Files: |
Yes |
| Captions: | Available on CD and Online University |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 98,729 Video Tutorials (23,265 free)
- Video Available as Flash or QuickTime
- Over 1026 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 