c++指针

1620阅读 0评论2014-01-02 zhang2428847702
分类:C/C++

1:

int *p;//指针p指向哪里?????

*p=200;

这两句将会发生错误。

因为计算机只是分配了用来存储地址的的内存。

但是木有分配用来存储指针所指向的数据的内存。。

2:

char *getname()

{

char temp[80];

cout<<"enter your name:"<

cin>>temp;

char *p=new char[strlen(temp)+1];

strcpy(p,temp);

return p;

}

此函数可以用来得到输入的字符串。

#include

#include

using namespace std;

void  main()

{

int a[5]={1,2,23,4,5};

int  *p=a;

cout<<*p<

cout<<*++p<

cout<<++*p<

cout<<(*p)++<

cout<<*p++<

}


上一篇:用List实现Stack基本功能
下一篇:Spring - lookup-method使用示例