Small problem

if you have pointer to char how do you call it for example
1
2
3
  void create(char *fname)//function prototype
char name[20]="name";
create(name);//should call be like this or is there an error whats the correct way 
Pointers and arrays are the same thing. So in your program, sending "name" to the function is perfectly fine.
Pointers and arrays are not the same thing.

However, when you use an array name by itself it easily degenerates into a pointer to the first element of the array.

Unless you plan to modify the array, you should declare your argument as const:

1
2
3
4
void create( const char* fname ); 

char name[20] = "name";
create( name );

Hope this helps.
What if we want to send the first letter of variable name than can we write
create(name,1);
Wait, what?

Do you mean you want to send the first char in a string to a function?

1
2
3
4
5
void foo( char c ) ...

char name[20] = "quux";

foo( name[0] );

[edit] You would really benefit from reading through this sites tutorials.
http://www.cplusplus.com/doc/tutorial/
Last edited on
Thank you :)
Topic archived. No new replies allowed.