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