字符数组(Character array)

//字符数组
#include <iostream>
#include <string.h>
using namespace std;
int main(int argc, char const *argv[])
{
    char x[] = "abcdefg";                             //字符串存储会默认后面加一个字符“\0”
    char y[] = {'a','b','c','d','e','f','g'};      //单字符存储则不会有“\0”
    cout << sizeof(x) << endl;   //sizeof 计算实际存储的字节数,包括"\0"           
    cout << sizeof(y) << endl;    //
    cout << strlen(x) << endl;   //strlen计数器,逐个计算所有遍历的字符不包括“\0”
    cout << strlen(y) << endl;
    return 0;
}

zl@LAPTOP-2ABL2N6V:/mnt/d/基础入门/08-数据结构$ g++ 1.cpp -o 1zl@LAPTOP-2ABL2N6V:/mnt/d/基础入门/08-数据结构$ ./187714zl@LAPTOP-2ABL2N6V:/mnt/d/基础入门/08-数据结构$

————————
//字符数组
#include <iostream>
#include <string.h>
using namespace std;
int main(int argc, char const *argv[])
{
    char x[] = "abcdefg";                             //字符串存储会默认后面加一个字符“\0”
    char y[] = {'a','b','c','d','e','f','g'};      //单字符存储则不会有“\0”
    cout << sizeof(x) << endl;   //sizeof 计算实际存储的字节数,包括"\0"           
    cout << sizeof(y) << endl;    //
    cout << strlen(x) << endl;   //strlen计数器,逐个计算所有遍历的字符不包括“\0”
    cout << strlen(y) << endl;
    return 0;
}

zl@LAPTOP -2abl2n6v: < / strong > < strong > / MNT / D / basic introduction / 08 – data structure < / strong > $G + + 1.cpp – O 1 < strong > zl@LAPTOP -2abl2n6v: / MNT / D / introduction to basics / 08 – data structure < / strong > $. / 187714 < strong > zl@LAPTOP -2abl2n6v: < / strong > < strong > / MNT / D / basic introduction / 08 – data structure < / strong >$