C语言-----内存与指针(3) How do you pass a string to a function如何给一个函数传入字符串作为参数:

来源:互联网 发布:java三大框架学习顺序 编辑:程序博客网 时间:2024/05/21 10:25
#include <stdio.h>void printAString(char msg[]){       printf("%s\n",msg);    printf("%lu\n",sizeof(msg));    }int main(int argc, const char * argv[]){    // insert code here...        printf("%ld\n",sizeof("hello"));        char s[]={'h','e','l','l','o'};    char message[]="good";    char * t=message;    printAString(s);    printAString(message);    printAString(t);    return 0;}

6           //  sizeof("hello")  是6, 

hello     

8         //为啥后面的都是8

good

8

good

8

 为啥是8;为啥没有打印出hello , good各自的长度,这很奇怪。

 

编译器此时认为msg是一个指针;




0 0