qq_40681494
qq_40681494
采纳率0%
2017-10-18 16:47

c语言,新人求教,关于解引用的问题

#include
int main(void)
{
const char * mesage = "wo,e";
printf("%s", mesage);
}
为什么不是printf("%s", mesage);?不用解引用吗?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

3条回答

  • Echo_of_Silence 白首少年 4年前

    C里面怎么会有引用?那是C++里的吧。

    点赞 评论 复制链接分享
  • u013022032 夏凌风 4年前

    printf中的%s是表示输出字符串,传入的是char *指针,直至遇到'\0'停止输出。如果像你所说的解引用,只会输出首字符“w".

    以下是Linux中关于printf关于%s的说明,仅供参考。
    s If no l modifier is present: The const char * argument is expected to be a pointer to an array of character type (pointer to a string). Characters from the array are
    written up to (but not including) a terminating null byte ('\0'); if a precision is specified, no more than the number specified are written. If a precision is
    given, no null byte need be present; if the precision is not specified, or is greater than the size of the array, the array must contain a terminating null byte.

              If an l modifier is present: The const wchar_t * argument is expected to be a pointer to an array of wide characters.  Wide characters from the array are converted to
              multibyte characters (each by a call to the wcrtomb(3) function, with a conversion state starting in the initial state before the first wide  character),  up  to  and
              including  a  terminating null wide character.  The resulting multibyte characters are written up to (but not including) the terminating null byte.  If a precision is
              specified, no more bytes than the number specified are written, but no partial multibyte characters are written.  Note that the precision  determines  the  number  of
              bytes written, not the number of wide characters or screen positions.  The array must contain a terminating null wide character, unless a precision is given and it is
              so small that the number of bytes written exceeds it before the end of the array is reached.
    
    点赞 评论 复制链接分享
  • weixin_40696743 weixin_40696743 4年前

    你的问题有问题,看不出你想表达什么

    点赞 评论 复制链接分享