Small problem
Dec 15, 2013 at 8:21pm
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
|
Dec 15, 2013 at 9:11pm
Pointers and arrays are the same thing. So in your program, sending "name" to the function is perfectly fine.
Dec 15, 2013 at 9:16pm
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.
Dec 16, 2013 at 6:43pm
What if we want to send the first letter of variable name than can we write
create(name,1);
Dec 16, 2013 at 7:08pm
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 Dec 16, 2013 at 7:09pm
Dec 17, 2013 at 12:49pm
Thank you :)
Topic archived. No new replies allowed.