I am new to C programming. and I know char * and char[] array are different. Yet, you can deduct the char[] to char * when it comes to a function param. So function declarations could be the same.
But how do I know if the function is specifically expecting a char array versus char * by looking at the signature (declaration)?
For example, if I am using a library header file and the function is below. How do I know which one to pass?
// somelib.h
void foo(char *bar);
Because if the function is modifying the bar parameter and if I pass a char *, it will get a segfault. This is for C, but would it be the same for C++?
You read the documentation. Short of using a proof language like Agda, the type system will never fully describe the function's contract. In C, read the docs.
In C++ you should never use
char*. Functions expecting a string should take anstd::string. Functions expecting a character that they wish to modify should use achar&, and in the rare case where you need an array of characters that is not a valid string,std::vector<char>should be used. There's never a use case for a raw pointer as a public function argument in modern C++.