[英]What is the difference between char *name[10] and char (*name)[10]?
[英]Difference between “char[] name” and “char name[]” as a function's argument in c
當定義這樣的函數時:
void myFunction(arguments){
// some instructions
}
使用char[] name
和char name[]
作為函數的參數之間有什么區別? 為什么不使用指向char的指針呢?
第一個( char[] name
)不會編譯,因為它是錯誤的語法。
函數實現的參數定義中的數組子腳本轉到(強制)參數的名稱。
正確的語法是第二個 :
char name[]
例:
void p(char[]); /* prototype */
void p(char name[]) /* implementation */
{
}
但是, char[] name
將被視為無效語法。
您將得到編譯錯誤。
0.c:3:14: error: expected ‘;’, ‘,’ or ‘)’ before ‘a’
int f(char []a){
^
不可能編譯這樣的代碼:
#include <stdio.h>
int f(char []a){
}
main(){
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.