&x evaluates to the adress of x in memory.
*(&x) evaluates to the someting as x.
Pointer advantages:
- More flexible pass-by-reference
- Manipulate comlex data structure efficiently
- Use polymorphism
Pointers are variables stroring memory address.
Declaring pointers:
int *ptr = &x;
As with any other variable, the value of a pointer is undefined until it is initialized , so it may be invalid.
References:
int y;
int &x = y;
Reference variable x becomes another name for the value of y in memory.
The usage of the * and & operators with pointers/references can be confusing. The * operator
is used in two different ways:
- When declaring a pointer, * is placed before the variable name to indicate that the variable being declared is a pointer – say, a pointer to an int or char, not an int or char value.
- When using a pointer that has been set to point to some value, * is placed before the pointer name to dereference it – to access or set the value it points to.
A similar distinction exists for &, which can be used either
- to indicate a reference data type (as in int &x;), or
- to take the address of a variable (as in int *ptr = &x;).
分享到:
相关推荐
Day 5 Functions Day 6 Basic Classes Day 7 More Program Flow Week 1 in Review Week 2 at a Glance Day 8 Pointers Day 9 References Day 10 Advanced Functions Day 11 Arrays Day 12 Inheritance ...
Sams Teach Yourself C++ in One Hour a Day ' In just one hour a day, you'll have all the skills you need to begin programming in C++. With this complete tutorial, you'll quickly master the basics and ...
Chapter 5: Advanced Data Types Chapter 6: Loops and Conditional Statements Chapter 7: Arrays and Pointers Chapter 8: Functions Chapter 9: Operator Overloading Chapter 10: Object Oriented Programming ...
5 Working with Expressions, Statements, and Operators 93 6 Organizing Code with Functions 127 7 Controlling Program Flow 167 8 Pointers Explained 203 9 Exploiting References 231 PART II: Fundamentals ...
Chapter 5. One dimensional Array. Chapter 6. Multi-Dimensional Array. Chapter 7. String (Character Array). Chapter 8. Your Brain on Functions. Chapter 9. Your Brain on Pointers. Chapter 10. Structure,...
It has been used to create almost every category of software imaginable and the list keeps growing every day. Cutting-edge applications, such as Arduino, embeddable and wearable computing are ready-...
We interact with hundreds of tiny computers every day that are embedded into our houses, our cars, our toys, and our work. As our world has become more complex, so have the capabilities of the ...
When I told him pointers, he told me to debug our link-list library on paper. If you read about 2000 lines of link-list library code, you will either learn pointers or go mad, and those may not be ...
A comprehensive index will support the C++ programmer in his/her day-to-day life. The book covers all the new C++11 library components, including Concurrency Fractional arithmetic Clocks and Timers ...
- Pointers Concepts - What is a pointer - How to declare a pointer - How to use a pointer Day-02 [23-02-2021]: - Declaring double pointer - Functions using pointer - Arrays using pointer - What is...
Chapter 5. One dimensional Array. Chapter 6. Multi-Dimensional Array. Chapter 7. String (Character Array). Chapter 8. Your Brain on Functions. Chapter 9. Your Brain on Pointers. Chapter 10. Structure,...
69.zip Smart Pointers and other Pointer classes 指针类(5KB)<END><br>70,70.zip Sortable CObArray class 对CObArray类排序(5KB)<END><br>71,71.zip Sortable CObList class 对CObList类排序(6...
Lesson 5: Concepts – Formulating and Implementing Resolution 81 Module 4: Troubleshooting Locking and Blocking Overview At the end of this module, you will be able to: Discuss how ...
CONTENTS 5 3 Machine-Level Representation of C Programs 89 3.1 AHistorical Perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 3.2 ProgramEncodings . . . . . . . . ....