Skip to content

Instantly share code, notes, and snippets.

@jasom
Created April 30, 2012 21:04
Show Gist options
  • Select an option

  • Save jasom/2562681 to your computer and use it in GitHub Desktop.

Select an option

Save jasom/2562681 to your computer and use it in GitHub Desktop.
Array arguments are really pointers
#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));
}
@jasom

jasom commented Apr 30, 2012

Copy link
Copy Markdown
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment