Checkout the error when I’m calling f2 !
Why this is happening? How to deal with this?
How to deal with char type formal arguments
hello @prerak_semwal
u are sending a string (“p” ) and trying to receive it as a char.
that is why the compiler is throwing error.
pass ‘p’ in place of “p”
Can you please explain in detail (laymen terms ) the difference in char[], char, *char, char[2]
Also please refer to following !
hello @prerak_semwal
char is a simple datatype to store charaters.
char [] this indicates an array of char where u havent sepcified its size.
char [2] this also indicated array of char but here u have mention the size (2).
char * -> this is pointer to char, i.e it will store address of char.
note when we pass char array in function then only base address of array is passed.
so char[], char * , char [2] inside function argument will receive base addrss and hecne they will have similar behaviour.
But if you notice in line14 , we have char[2] as formal parameter so shouldn’t it only take first two characters or raise error ?
Also, whenever we see * in c++, we are always talking about addresses ??
…
doesnt matter how u write (char[],char[2],char * )
in all the cases only base address is passed.
it is also used as dereferencing operator. i.e to get value present at particular address we use *
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.