Gotchas: Difference between revisions

m
Line 203:
 
As using <code>sizeof</code> on a memory address returns the number of bytes that the CPU's instruction pointer register can hold, you'll get the same return value from <code>gotcha</code> regardless of how many elements the array has. When C programmers talk about "arrays decaying into pointers" this is what they're referring to.
 
In order for a function to use an array's intended size, it must be passed in as a separate argument.
<syntaxhighlight lang="C">int foo(char buf[],int length){}
 
int main()
{
char myArray[30];
int j = foo(myArray,sizeof(myArray)); //passes 30 as the length parameter.
}
 
}</syntaxhighlight>
 
===gets()===
1,489

edits