c语言
①二维数组
#include<stdio.h>
void main()
{
int i;
char sz[3][20]={"优快云","世界","你好"};
for(i=0;i<3;i++)
{
printf("%s ",sz[i]);
}
printf("\n");
}
运行结果:
优快云 世界 你好
Press any key to continue
②指针
#include<stdio.h>
void main()
{
int i;
char *p[3]={"hello","世界","hi"};
for(i=0;i<3;i++)
{
printf("%s ",p[i]);
}
printf("\n");
}
运行结果:
hello 世界 hi
Press any key to continue
C++
#include<iostream>
#include<string>
using namespace std;
int main()
{
string h[3]={"第一个字符串","第二个字符串","第三个字符串"};
for(int i=0;i<3;i++)
{
cout<<h[i]<<" ";
}
cout<<endl;
return 0;
}
运行结果:
第一个字符串 第二个字符串 第三个字符串
--------------------------------
Process exited after 3.853 seconds with return value 0
请按任意键继续. . .