In C++, you probably shouldn't be doing manual string manipulations like these at all, std::string is preferred. I'll assume you are using C, since #include <stdio.h>
is obsolete style in C++ anyhow.
When we call function passing by value, we are making a copy in memory of the actual parameters' value.
Indeed. In this case, a copy of the pointer to the string is made.
The question is: does the function know how much space its parameters occupy in memory?
Sure, simply take sizeof(X)
and you'll get the size of the pointer (4 bytes on 32 bit system). As for whether a "function knows" the nature of the data which that pointer points at... it depends on the programmer.
If the programmer of the function has properly documented that the pointer must point at an allocated array of 100 bytes, then the function is free to assume that it was passed such a pointer.
If the programmer haven't documented a thing, then nobody would know how to use the function, in which case nothing in the program makes any sense. Unless the function definition is available to the caller.
Alternatively, you could write self-documenting code: void func(char X[100])
. This code is 100% equivalent to what you have: it also passes a pointer. But there are still no guarantees that this pointer points at an array of 100 bytes, we have merely added a hint to the caller that we expect one. If they pass something else, the program will still likely halt and catch fire.
If you are wondering how to find out the size of the data pointed-at, without actually passing it as parameter, read this.