AD

c + + const pointers and references

#include "stdafx.h"
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    /****const  Pointer  ****/
    const double pi = 3.14;
        //double *p = &pi;// Error, const object address can only be passed on to    Points to a const object    Pointer  
        const double *p = 0;
        p = &pi;
        //*p += 1.4;// Error, cannot    Pointer to a pointer to a const object    Modify a const object    The value of the  
        double age = 2.2;
        p = &age;// Pointer to a pointer to a const object    Can point to non-  const Object  
        //*p += 1.2;// Pointer to a pointer to a const object    Links to non-  const Object  , You cannot modify the value of the non-const objects  
        cout<<*p<<endl;

        int num = 0;
        int num1 = 1;
        int *const cur = &num;// Define a link to a non-const objects    const Pointer  
        //cur = &num1;// You cannot modify the value of the cur  

        /****const  Reference  ****/
        double val = 3.2;
        const double &dr = val + 1.0;
        const int &ir = 1024;
        const int &ir1 = val;
        //int &ir2 = 1024;// Non-const references    Cannot point to a constant  
        //int &ir3 = val;// Non-const references    Cannot be    Implicit conversions  ( Cannot be converted to a double  int)
        //double &ir4 = val + 1.2;// Non-const references    No addition operation  
        double &ir5 = val;
        ir5 = 4;
        cout<<val<<endl;
        const int ival = 1024;
        int const &s1 = ival;
        const int *const &s = &ival;
}
 
标签: lt, amp, cur, s1, pi, int num, pointers, iostream, endl, stdafx, argc, ival, c const, ir1, ir2
分类: CPP
时间: 2010-10-15

相关文章

  1. c + + difference between pointers and references in [turn]

    Switch: c + + pointers and references in the difference between the original address: http://blog.sina.com.cn/ ...
  2. The difference between pointers and references

    Pure as to their review, and summarize: 1,. Distinction between non-empty Under any circumstances can not use ...
  3. 2000个软件开发领域的高频特殊词及精选例句(七)

    superword是一个Java实现的英文单词分析软件,主要研究英语单词音近形似转化规律.前缀后缀规律.词之间的相似性规律等等. 1701.单词 jpql 的匹配文本: You will learn how to imp ...
  4. C + +, the difference between references and pointers

    A recent weeks, are conducting research SDL, feeling this thing is not bad. I started the course is Uvi Studio ...
  5. "Pointing to const object pointer" and "const pointer"

    const is C + + introduced a new keyword, it is C + + programming is a big convenience. Point to const object p ...
  6. C + + pointer reference transmission and transfer difference (further order)

    Conceptually. In essence, the pointer variable address is stored as a variable, is logically independent, it c ...
  7. From C To C + + Course Design

    1) The preliminary understanding of programming language development process. The significance of object-orien ...
  8. Difference between pointer and reference parameters

    Pointers and references to learn C + + has been a difficult time, do not know when to use the pointer, when to ...
  9. Allocator is a C + + language standard library, one of the most mysterious part of the

    Allocator is a C + + language standard library, one of the most mysterious part. They are rarely used explicit ...
  10. Binary tree and binary search tree

    Binary tree and binary search tree Pointers and references: int count = 18; int * ptr = &count; int count ...
  11. C + + programming ideas

    C + + programming ideas Basic information Original title: Thinking in C + + Volume One: Introduction to Standa ...
  12. GNU的C++代码书写规范,C语言之父Dennis Ritchie亲自修订

    C++ Standard Library Style Guidelines DRAFT 1999-02-26 ------------------------------------- This library is w ...
  13. Designing Qt-Style C++ APIs - 少即是多 - 专注

    Designing Qt-Style C++ APIs http://doc.trolltech.com/qq/qq13-apis.html by Matthias Ettrich We have done substa ...
  14. API的设计原则 API Design Principles

    API Design Principles One of Qt's most reputed merits is its consistent, easy-to-learn, powerfulAPI. This docu ...
  15. C + + Study Notes - 5

    Pointer and typedef The use of pointers in typedefs (Section 2.6, p. 61) often leads to surprising results. He ...
  16. JAVA Design Pattern superficial glance

    Today, learn more advanced knowledge of design patterns. I have some very honest, the first large, almost runn ...
  17. poj2739 problem solving report

    1. Algorithm sieve method to find all the prime numbers less than 10,000, deposited in the array. Then for eac ...
  18. Programming Language Comparison: AS vs C + + vs Java vs Python

    <br /> Function whether to support the participation? (Based on C + +) AS: support. Through the pass by ...
  19. Database design - Restricted Category

    Constraint modeling: First, the classification of constraints can be divided into: 1, the key (key) is the ent ...