-
int const a = 3; int *p = &a; a被const修飾,限制比*p大,權(quán)限大的變量不能指向權(quán)限小的變量查看全部
-
#include<iostream> using namespace std; //void fun(const int &a,const int &b); //錯誤! void fun(int &a, int &b);//形參可以影響實參 int main(void) { int x = 3; int y = 5; fun(x,y); system("pause"); return 0; } void fun(int &a,int &b)//函數(shù) { a = 10; b = 20; }查看全部
-
內(nèi)存 操作系統(tǒng) 申請/歸還查看全部
-
引用是變量的別名。查看全部
-
#include<iostream> using namespace std; int main(void) { int x = 3; int y = 5; int const * p = &x; //聲明(int const * p)和初始化(p = &x)在一塊 cout << *p << endl; p = &y; //賦值 cout << *p <<endl; system("pause"); return 0; }查看全部
-
#include<iostream> using namespace std; int main(void) { int x = 3; int y = 5; int * const p = &x; //const修飾的是變量p,這時候p就是常量 *p = 10; //p指向 &x,*p = *&x = x cout << x <<endl; system("pause"); return 0; }查看全部
-
#include<iostream> using namespace std; int main(void) { int x = 3; int const *p = &x;//const int * p = &x; *p = 5;//錯誤 不能給常量賦值 x = 5;//正確 system("pause"); return 0; }查看全部
-
#include<iostream> using namespace std; #define X 3 //宏定義,編譯的時候計算機不再檢查語法類型 int main(void) { const int x = 3;//可以有類型,編譯的時候需要檢查語法錯誤 system("pause"); return 0; }查看全部
-
#include<iostream> using namespace std; int main(void) { const int x = 3; x = 5; //x不能給常量賦值 system("pause"); return 0; }查看全部
-
權(quán)限小的變量能夠指向權(quán)限大的變量,權(quán)限大的變量不能指向權(quán)限小的變量; const int x = 3; int *y = &x; y是變量權(quán)限大,x被const修飾權(quán)限小【×】 int x = 3; const int *y = &x; y被const修飾,權(quán)限小;x是變量,權(quán)限大【√】查看全部
-
const在誰(*/字母)的前面誰就不能變,就近原則嘛查看全部
-
#include <string.h> #include <iostream> using namespace std; int main(void) { //在堆中申請100個char類型的內(nèi)存 char *str =new char[100]; //拷貝Hello C++字符串到分配的堆中的內(nèi)存中 strcpy(str, "Hello imooc"); //打印字符串 cout<<str<<endl; //釋放內(nèi)存 delete []str; str=NULL; return 0; }查看全部
-
塊內(nèi)存的申請與釋放查看全部
-
int *p=new int(20);等價于int *p=new int; *p=20;查看全部
-
申請內(nèi)存要判斷是否成功,釋放內(nèi)存需要設(shè)空指針查看全部
舉報
0/150
提交
取消