A detailed description of the pointer

Source: Internet
Author: User

NULL Pointer#include<iostream>using namespacestd;intMain () {//Assigning a NULL value to a pointer variable is a good programming practice if there is no exact address to assign a value to. A pointer that is assigned a null value is called a null pointer.     int*ptr =NULL; cout<<"ptr is"<< ptr <<Endl; if(PTR) {cout<<"Do not print"<<Endl; } Else{cout<<"Run"<<Endl; }        return 0;}/*vim:set ts=4 sw=4 sts=4 tw=100*/
arithmetic operations for pointers "+ +-+-"#include<iostream>using namespacestd;Const intMAX =3;intMain () {int var[MAX] = {Ten, -, $}; int*ptr; PTR=var;  for(intI=0; i < MAX; i++) {cout<<"Address of Var ["<< I <<"] ="; cout<< ptr <<Endl; cout<<"Value of var["<< I <<"] ="; cout<< *ptr <<Endl; PTR++; }    return 0;}/*vim:set ts=4 sw=4 sts=4 tw=100*/
Comparison of Pointers#include<iostream>using namespacestd;Const intMAX =3;intMain () {int var[MAX] = {Ten, -, $}; int*ptr; *(var+2) = -; PTR=var;  while(PTR <= &var[MAX-1]) {cout<< ptr <<"&"<< *ptr <<Endl; PTR++; }    return 0;}/*vim:set ts=4 sw=4 sts=4 tw=100*/

A detailed description of the pointer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.