#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;
}
#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;
}
#include <iostream>
using namespace std;
int main(void)
{
cout << 6 << endl;
cout<<8<<endl;
return 0;
}
這也可以通過..嘖嘖
using namespace std;
int main(void)
{
cout << 6 << endl;
cout<<8<<endl;
return 0;
}
這也可以通過..嘖嘖
很多人的迷惑
&的意思:
取地址符,這時候他用于數(shù)據(jù)的前面,比如int a=&b;
C++里還使用&作為引用符,如果你確認程序是標準的C而非C++的話,那么可以排除是引用了。引用也用于數(shù)據(jù)前面,它只在定義和聲明時使用,如int &othername=name;
int &a=b; //定義時使用在等號左側(cè),是引用
int *a=&b; //在等號右側(cè),并單獨在數(shù)據(jù)之前,是取地址
int a=(&b) & 0xffff; //第一個&是用于取b的內(nèi)存中的地址,第二個&是按位與,即保留b地址值的低16位,高16位數(shù)值被清零(32位處理器下).
&的意思:
取地址符,這時候他用于數(shù)據(jù)的前面,比如int a=&b;
C++里還使用&作為引用符,如果你確認程序是標準的C而非C++的話,那么可以排除是引用了。引用也用于數(shù)據(jù)前面,它只在定義和聲明時使用,如int &othername=name;
int &a=b; //定義時使用在等號左側(cè),是引用
int *a=&b; //在等號右側(cè),并單獨在數(shù)據(jù)之前,是取地址
int a=(&b) & 0xffff; //第一個&是用于取b的內(nèi)存中的地址,第二個&是按位與,即保留b地址值的低16位,高16位數(shù)值被清零(32位處理器下).
2017-05-16
#include <iostream>
using namespace std;
int main(void)
{
cout<<"老師講課棒棒噠!"<<endl;
return 0;
}
using namespace std;
int main(void)
{
cout<<"老師講課棒棒噠!"<<endl;
return 0;
}
2017-05-14
已采納回答 / qq_HaibaraDu_0434753
不能直接用,因為sizeof(numArr)并不是數(shù)組長度,而是數(shù)組長度與sizeof(int)的乘積。想用sizeof的話也可以,cout << getMax(numArr,sizeof(numArr)/sizeof(int)) << endl;
2017-05-14