strlen 与 sizeof

#include <stdio.h>
#include <string.h>
#include <iostream>

int main()
{
  char name[7] = "morgan";
  std::cout << strlen(name) << "  " << sizeof(name) << std::endl;
  //6   7

  const char* name2 = "morgan";
  std::cout << strlen(name2) << "  " << sizeof(name2) << std::endl;
  //6   8

  std::cout << strlen("morgan") << "  " << sizeof("morgan") << std::endl;
  //6   7

  return 0;
}

  

posted @ 2021-05-16 17:23  upupon  阅读(26)  评论(0编辑  收藏  举报