1.字符串数组,字符串指针可以直接输出

char s2[30]="I am a student";
cout<<s2<<endl;
char *p="I am a student";
cout<<p<<endl;
cout<<p[2]<<endl;

2.指针变量p分配4个存储单元。

用指针变量处理字符串,要比用数组处理字符串方便。
指针变量用于存放变量地址,而地址通常为4字节,所以指针变量的长度均为4个字节。

#include<stdio.h>

void main()
{
    int c=sizeof(char);//1
    int i=sizeof(int);//4
    int l=sizeof(long);//4
    int d=sizeof(double);//8
    int p=sizeof(int *);//4
    int q=sizeof(char *);//4

    printf("%d\t%d\n",c,i);
    printf("%d\t%d\n",l,d);
    printf("%d\t%d\n",p,q);
}
View Code

相关文章:

  • 2022-12-23
  • 2021-07-21
  • 2021-05-15
  • 2021-05-25
  • 2021-07-27
  • 2022-12-23
  • 2022-12-23
  • 2022-02-05
猜你喜欢
  • 2021-07-05
  • 2022-01-02
  • 2021-09-11
  • 2022-01-11
  • 2021-07-03
  • 2022-12-23
相关资源
相似解决方案