Created
April 30, 2012 21:04
-
-
Save jasom/2562681 to your computer and use it in GitHub Desktop.
Array arguments are really pointers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void foo(char []); | |
void bar(char *); | |
int main() | |
{ | |
static char x[100]; | |
printf("%ld\n",sizeof(x)); | |
foo(x); | |
bar(x); | |
} | |
void foo(char x[]) | |
{ | |
printf("%ld\n",sizeof(x)); | |
} | |
void bar(char *x) | |
{ | |
printf("%ld\n",sizeof(x)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I propose that there is no code you can write inside foo() / bar() that would let you tell whether x was declared as [] or * in the argument list. That is to say if the function bodies are identical, the behavior will be identical.