C-当把数组传递给函数


#include <stdio.h>

/**
 * C语言中,数组的名称就是 一连串连续内存的起始地址,
 * 因此给数组传递给函数,传递的就是数组元素类型的指针
*/

void hello_0(char msg[20]);
void hello_1(char msg[]);
void hello_2(char *msg);

int main() {

    char msg[20] = "hello kitty";
    char notice[40] = "this is a notice to kitty.";
    hello_0(msg);
    hello_1(msg);
    hello_2(msg);

    hello_0(notice);
    hello_1(notice);
    hello_2(notice);
    return 0;
}

void hello_0(char msg[20]) {
    printf("0 msg is [%s]\n", msg);
}

void hello_1(char msg[]) {
    printf("1 msg is [%s]\n", msg);
}

void hello_2(char *msg) {
    printf("2 msg is [%s]\n", msg);
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM