如何在C++环境下输出字符数组的首地址,并验证其正确性

来源:百度知道 编辑:UC知道 时间:2024/05/17 08:49:50

#include<iostream>
using namespace std;
void main()
{
char str[]="hello";
cout<<&str<<endl;
}

void main()
{
char s[]="fsjfsh";
printf("%d",s);
}
打印出来的就是地址

#include <iostream.h>

void main ()
{
char *str="string"; //字符串str
cout<<&str<<endl; //屏幕输出字符串str的首地址
}

字符数组的首地址可以是字符数组名,也可以是第一个字符的地址
char ch[20]="xxxxx";
char* p;
p=ch; //数组名就是首地址
p=&ch[0]; //第一个字符的地址也是首地址