const在*外,p可以改指向的變量,但已指向的變量值無法通過p來改變。
在*內(nèi),可以通過p改變指向變量的值,但無法改指向的變量。
在*內(nèi),可以通過p改變指向變量的值,但無法改指向的變量。
2016-02-22
int getMax(int * arr, int count)
{
int maxNum = *arr;
for(int i = 1; i < count; i++) {
if(* ++arr > maxNum) {
maxNum = *arr;
}
}
return maxNum;
}
int main(void) {
int numArr[8] = {3, 8, 6, 5, 0, 1, 2, 4};
cout << getMax(2, 6) << endl;
cout << getMax(numArr, 8) << endl;
return 0;
}
{
int maxNum = *arr;
for(int i = 1; i < count; i++) {
if(* ++arr > maxNum) {
maxNum = *arr;
}
}
return maxNum;
}
int main(void) {
int numArr[8] = {3, 8, 6, 5, 0, 1, 2, 4};
cout << getMax(2, 6) << endl;
cout << getMax(numArr, 8) << endl;
return 0;
}
#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;
//釋放內(nèi)存
delete[] str;
str = NULL;
return 0;
}
#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;
//釋放內(nèi)存
delete[] str;
str = NULL;
return 0;
}