const int* p=&a 等價于 const int *p=&a;
int x=3; 等價于 int x=3; 建議將& 與 *符號位于 類型聲明后 (int& y=x; 而不是 int &y=x;)以便于新同學區分取址符
int &y=x; int& y=x;
int x=3; 等價于 int x=3; 建議將& 與 *符號位于 類型聲明后 (int& y=x; 而不是 int &y=x;)以便于新同學區分取址符
int &y=x; int& y=x;
2015-06-16
已采納回答 / JACK630
上面一組:const int x = 3 表示x為一個常量,其值為3,且x的值是不能改變的;int *y = &x 定義了一個指針變量y,y指向x,y存放的是x的地址,改變y的的值也就相當于改變了x的值,這與常量x不能被改變相沖突,所以說有危險;下面一組:可以正常使用;
2015-06-05
#include <string.h>
#include <iostream>
using namespace std;
int main(void)
{
//在堆中申請100個char類型的內存
char *str = new char[100];
//拷貝Hello C++字符串到分配的堆中的內存中
strcpy(str, "Hello imooc");
//打印字符串
cout<<str<<endl;
//釋放內存
delete str;
str=NULL;
return 0;
}
#include <iostream>
using namespace std;
int main(void)
{
//在堆中申請100個char類型的內存
char *str = new char[100];
//拷貝Hello C++字符串到分配的堆中的內存中
strcpy(str, "Hello imooc");
//打印字符串
cout<<str<<endl;
//釋放內存
delete str;
str=NULL;
return 0;
}