`
wihoho
  • 浏览: 8940 次
  • 性别: Icon_minigender_1
  • 来自: Singapore
最近访客 更多访客>>
社区版块
存档分类
最新评论

Day 5: Pointers

阅读更多

&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;). 
0
0
分享到:
评论

相关推荐

    sams teach yourself c++ in 21 days

    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 (8th Edition).pdf(21天学通C++ 第8版 英文版)

    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 ...

    Learn.Cplusplus.In.A.DAY.1519318588.epub

    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 ...

    [Teach.Yourself.C.in.One.Hour.a.Day(6th,2008)].Jesse.Liberty.文字版

    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 ...

    C.Programming.Step.By.Step.Beginners.To.Experts.Edition.B011EXMV7Q

    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,...

    Advanced Topics in C.pdf

    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-...

    Embedded.Systems.Introduction

    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 ...

    Linq查询的基本语法(全部在一个程序中)

    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 ...

    The C++ Standard Library 2nd Edition(高清)pdf

    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 ...

    DSTOT

    - 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...

    C.Programming.Professional.For.Beginners.B011A2PX30

    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,...

    Visual C++ 编程资源大全(英文源码 表单)

    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...

    微软内部资料-SQL性能优化3

    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 . . . . . . . . ....

Global site tag (gtag.js) - Google Analytics