`
xiaoer_1982
  • 浏览: 1882590 次
  • 性别: Icon_minigender_2
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

c++ is on the way 3

阅读更多

问题:指针和引用之间的关系

指针的行为像一个引用,它是其他一些对象的别名。但是指针与引用之间的一个巨大差别是是指针并不永久依附于对象——它们可以删除。程序员可以让指针指向另一个对象,或者指向空。引用则必须在定义时初始化。事实证明,当算法使用索引而不是指针来表达时,编译器能实现更大的优化,这与一般认为使用指针效率高的观念是不同的。所以在迫不得已的情况下再使用指针吧,否则用引用会好很多。

指针使用:

int *pValue;

int TheValue=10;

pValue = &TheValue;

引用使用:

int TheValue=10;

int &aliasValue = TheValue;//引用TheValue

aliasValue = 20;//通过别名改变TheValue

不要在可以使用索引的地方使用指针。

分享到:
评论

相关推荐

    C++17: the complete guide

    Although it is not as big a step as C++11, it contains a large number of small and valuable language and library features, which again will change the way we program in C++. This applies to both ...

    The C++ Standard Library 2nd 原版pdf by Josuttis

    I learned C++11 the hard way. Because I didn’t follow the standardization as it was happening I started to look at C++11 about two years ago. I really had trouble understanding it. But the people on ...

    C++Ox: The Dawning of a New Standard

    The journey of C++ from its early days as a pre-processor to its current form as a sophisticated and highly capable language is documented in a timeline that covers each step along the way. This ...

    C++ Templates - The Complete Guide

    We’ve now lived over 20 years with C++ templates, but the C++ programmers’ community still regularly finds new fundamental insights into the way they can fit in our software development needs....

    Modern C++ Programming Cookbook

    The latest versions of C++ have seen programmers change the way they code, giving up on the old-fashioned C-style programming and adopting modern C++ instead. Beginning with the modern language ...

    Moving from C to C++

    the set of features I explain in each chapter is based on the way that I see a particular type of problem being solved with the language. In this way I hope to move you, a little at a time, from ...

    Professional C++, 4th Edition

    The C++17 release includes changes that impact the way you work with C++; this new fourth edition covers them all, including nested namespaces, structured bindings, string_view, template argument ...

    Ivor Horton’s Beginning Visual C++ 2010 英文版 PDF 超清晰版

    With this book by your side, you are well on your way to writing applications in both versions of C++ and becoming a successful C++ programmer. Ivor Horton's Beginning Visual C++ 2010: Teaches the ...

    C++17.STL.Cookbook

    C++ has come a long way and is in use in every area of the industry. Fast, efficient, and flexible, it is used to solve many problems. The upcoming version of C++ will see programmers change the way ...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    Note that this guide is not a C++ tutorial: we assume that the reader is familiar with the language. Header Files In general, every .cc file should have an associated .h file. There are some common ...

    Essential C++ 中文版

    It focuses on the elements of C++ programming that you are most likely to encounter and examines features and techniques that help solve real-world programming challenges. Essential C++ presents the ...

    Accelerated C++: Practical Programming by Example

    With its innovative approach to teaching the language, Accelerated C++ will challenge readers in the right way. It suggests that you don’t need to learn C to be productive in C++. Written in an ...

    Exploring the Raspberry Pi 2 with C++.pdf 2016

    and move into installing a custom kernel, creating a clock, learning the ins and outs of the GPIO interface, and pick up some useful C++ skills along the way. Warren Gay, author of Mastering the ...

    Practical C++ Financial Programming.pdf

    This is a hands-on book for programmers who want to learn about how C++ is used in the financial industry. The book concentrates on the parts of the language that are more frequently used to write ...

    Teach yourself C++

    Learning C++ by doing is the best way—so try the rich variety of code samples in this book hands-on and help yourself improve your programming proficiency. These code snippets have been tested using ...

    C++17 STL Cookbook

    C++ has come a long way and is in use in every area of the industry. Fast, efficient, and flexible, it is used to solve many problems. The upcoming version of C++ will see programmers change the way ...

    teach yourself c++ in 21 days

    新手自学 C++ 不错的教程 ... Join the leagues of thousands of programmers and learn C++ ... C++ is the preferred language for millions of developers-make Sams Teach Yourself the preferred way to learn it!

    Practical C++ Programming C++编程实践

    Templates: The Hard Way Templates: The C++ Way Function Specialization Class Templates Class Specialization Implementation Details Advanced Features Summary Programming Exercises 25. Standard ...

Global site tag (gtag.js) - Google Analytics