-
void fun(int i,int j = 5 ,int k = 10); void fun(int i ,int j ,int k) 這樣編譯不會(huì)報(bào)錯(cuò)查看全部
-
const(控制變量是否可以變化) const int x=3;(則此時(shí)x為常量,不可進(jìn)行再賦值) const與指針類型 const int *p=NULL; int const *p=NULL;(兩種寫法完全等價(jià)) int *const p=NULL; const int *const p=NULL; int const *const p=NULL;(這兩種寫法也是完全等價(jià)的) int x=3; const int *p=&x; *p=4(錯(cuò)誤,因?yàn)閏onst指定的為*p);p=&y;(正確) int x=3; const int *const p=&x; p=&y(錯(cuò)誤,因?yàn)閏onst指向的為p,只能為x的地址) const與引用 int x=3;const int &y=x; y=10(錯(cuò)誤,y通過const限定只能為x的別名,值為3) 總結(jié): const int x=3;int *y=&x;(這種寫法是錯(cuò)誤的因?yàn)閤本身定義為const,在用一個(gè)可變的指針指向,那么就有用指針改變x值得風(fēng)險(xiǎn),這是系統(tǒng)所不允許的); int x=3; const int *y=&x;(正確,這樣保證了指針對(duì)x只有可讀性,而沒有可寫性)查看全部
-
int *p = &a; int *&q = p; *q = 20;查看全部
-
const &z=x; z為x的引用 加const修飾 z變?yōu)槌A坎荒茉俳oz賦值查看全部
-
*const p=&x; p變成了常量 p就不能再指向y 但可以給*p賦值查看全部
-
const *p=&x; p還能指向y查看全部
-
上錯(cuò)下對(duì)查看全部
-
#include<iostream> using namespace std; int getMax(int a, int b) { return a>b ? a:b; } int getMax(int *arr; int count) { int maxNum=arr[0]; for (int i =1; i<count; i++) { if(maxNum<arr[i]) { maxNum=arr[i]; } } return maxNum; } int main() { int numArr[3]={3, 8, 6}; cout<<getMax(numArr,3)<<endl; cout<<getMax(numArr[0],numArr[2])<<endl; return 0; }查看全部
-
const查看全部
-
C C++中內(nèi)存申請(qǐng)與釋放 C{ malloc free },C++{new delete} int *p = new int[100]; | int *p = new int; | int *p; delete []p; | delete p; | p = (int *) malloc(sizeof(int)); p = NULL; | p = NULL; | free(p);查看全部
-
函數(shù)默認(rèn)參數(shù), 有什么用呢?查看全部
-
````查看全部
-
申請(qǐng)與釋放內(nèi)存查看全部
-
```查看全部
-
strcpy(s1,s2);strcpy函數(shù)的意思是:把字符串s2中的內(nèi)容copy到s1中,連字符串結(jié)束標(biāo)志也一起copy查看全部
舉報(bào)
0/150
提交
取消