96.1k views
4 votes
Write statementsto show how finding the length of a character array char [ ] differs from finding the length of a String object str.

User Yamu
by
4.2k points

1 Answer

2 votes

Answer:

Length of char array: sizeof(arr)

Length of a string object: myString.length()

Step-by-step explanation:

The sizeof approach is generally not recommended, since this information is lost as soon as you pass the array to a function, because then it becomes a pointer to the first element.

User Mergenchik
by
4.8k points