hi @rssrivastavarohan passing by reference is basically passing a pointer only. In C language the syntax is actually like
func(int *val) {
//do stuff
}
main(){
int val;
func(&val);
}
but it can be very complicated to use the values passed like these in the functions because you will have to use dereference pointer all the time, whenever you try to use that value (because “val” is a pointer in the function, not an int). So in c++ the syntax is made a little better by allowing us to write it like this
func(int &val) {
//do stuff
}
main(){
int val;
func(val);
}
now we can use “val” directly.
Coming to your question, arrays are basically pointers to the first element of the array. So you dont need to send them by reference, they are sent by reference by default. This is why you can also use a pointer while passing an array. But all the other datatypes need to be sent the conventional way because they are not pointers to anything.
Also, remember that “string” datatype and a character array may share some functionalities but they are not the same and hence some syntax differs.