Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Re: How is it w...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 5 Topic 26072 of 26972
Post > Topic >>

Re: How is it working? Am I doing it right?

by roberson@[EMAIL PROTECTED] (Walter Roberson) May 5, 2008 at 04:11 PM

In article
<d009b12e-13ff-44bd-a75b-b66a58854ca0@[EMAIL PROTECTED]
>,
Benoit Lefebvre  <benoit.lefebvre@[EMAIL PROTECTED]
> wrote:

>How come the value of the "word" variable change when using the
>testfunct function?  Am I sending a pointer to the word variable to
>this function or whatever ??

>int testfunct (char *myword)
>{
>  strcpy(myword,"hello");
>
>  return 0;
>}

>int main (int argc, char *argv[])
>{
>  char word[100];
>
>  strcpy(word,"weeee");
>  printf("WORD: %s\n", word);
>  testfunct(word);

When you pass an array name as a function parameter, it gets silently
converted into a pointer to the first element of the array.

>  printf("WORD: %s\n", word);
>
>  return 0;
>}

So yes, the above is fine / legal / well-defined, as long as testfunct()
does not write more characters into myword than the object is defined
to hold.
-- 
  "The art of storytelling is reaching its end because the epic
  side of truth, wisdom, is dying out."       -- Walter Benjamin
 




 5 Posts in Topic:
How is it working? Am I doing it right?
Benoit Lefebvre <benoi  2008-05-05 08:54:09 
Re: How is it working? Am I doing it right?
roberson@[EMAIL PROTECTED  2008-05-05 16:11:48 
Re: How is it working? Am I doing it right?
Keith Thompson <kst-u@  2008-05-05 09:39:15 
Re: How is it working? Am I doing it right?
Keith Thompson <kst-u@  2008-05-05 09:37:46 
Re: How is it working? Am I doing it right?
"Jim Langston"   2008-05-05 22:54:32 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 16:08:21 CDT 2008.