#include "stdafx.h"
#include "iostream"
#include <iomanip>
#include<stdlib.h>
//using std::cin;
//using std::cout;
//using std::setw;
//using std::endl;
//#define n 5
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int i,m[]={0,1,2,3,4,5,6,7,8,9};
int *p=&m[0];
cout<<*p<<endl; //0
cout<<*p++<<endl;//0
cout<<*p<<endl;//1 指针指在1的位置
cout<<*++p<<endl;//2指针指到2的位位置
cout<<*p<<endl; //2
cout<<p<<endl;
cout<<&*p<<endl;
cout<<*(++p)++<<endl;//3
cout<<*p<<endl;//指向4
cout<<++*p++<<endl;//指向5
return 0;
}
++的优先级别高于*
指针与字符串
#include "stdafx.h"
#include "iostream"
#include <iomanip>
#include<stdlib.h>
//using std::cin;
//using std::cout;
//using std::setw;
//using std::endl;
//#define n 5
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{ char x[3]={'q','q','\0'};
char *p="i am a boy";
cout<<p<<endl;
cout<<x<<endl;
return 0;
}
输出为:
i am a boy
指针与引用,
引用其实就是一个变量的别名
#include "stdafx.h"
#include "iostream"
#include <iomanip>
#include<stdlib.h>
//using std::cin;
//using std::cout;
//using std::setw;
//using std::endl;
//#define n 5
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int i="10";
int &ir=i;
cout<<ir<<endl;//10
int *p=&ir;
cout<<*p<<endl;//10
p=&ir;
cout<<*p<<endl;//10
int x="3";
p=&x;
cout<<*p<<endl;//3
return 0;
}
文章评论(0条评论)
登录后参与讨论