空终止字符串 [英] Null-Terminated string

查看:371
本文介绍了空终止字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下哪个是以空字符结尾的字符串?

  char * str1 =这是一个字符串。 
char * str2 =这是一个字符串。\0;
char str3 [] =这是一个字符串。
const char * str4 =这是一个字符串。
const char * str5 =这是一个string.\0;
const char str [] =这是一个字符串。


解决方案


  • 全部: literal是一个空结尾字符串

  • str2 str5






    • char * str1 应为 const char * str1

    • char * str2 应为 const char * str2


    Which of the following are null-terminated string?

    char *str1 = "This is a string.";
    char *str2 = "This is a string.\0";
    char str3[] = "This is a string.";
    const char *str4 = "This is a string.";
    const char *str5 = "This is a string.\0";
    const char str6[] = "This is a string.";
    

    解决方案

    • All : a string literal is a null terminated string
    • str2 and str5 have the particularity of being doubly null-terminated strings

    Also :

    • char *str1 should be const char *str1
    • char *str2 should be const char *str2

    这篇关于空终止字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆