How do I get the size of char* arr[] ?

If there is a second variable or function parameter holding the size, then use it. Otherwise, you should know what’s the agreement on terminating the array of characters. By default strings are zero terminated (\0). That means you should run a loop until you find the zero value. The size would be whatever number of elements there are before zero. The edge case is char* pointer points to “\0”. Under circumstances, the agreement can be different. For example, (a) fixed size array without terminator, (b) different than “\0” terminator, (c) combination of predefined terminator including “\0” and maximum allowed size. As an added sanity check, you may also need to check if pointer is not zero on its own. All of the above is for finding the number to f elements in the array. If you need to know the number of bytes, then use sizeof(char) to get the number of bytes per element, multiple it by number of elements in the array and adjust for terminator, if present. The size of terminator is the same as sizeof(char).

/r/C_Programming Thread