The string length is 5 - which is NOT the same thing as the size of the array.
Yes - I didn't read the OP's post carefully. strlen(array) returns the number of characters (assuming array is a character array) are in the array.
Edit:
A simple program that might help:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
usingnamespace std;
int main()
{
constint MAX = 10; //must be constant value, so compiler knows it will not change.
char s1[MAX] = "susan";
cout << s1 << "\n";
cout << sizeof(s1) << "\n"; //is the size of the array s1[], which is defined as MAX.
cout << strlen(s1); //the number of characters in 'susan' - 5.
getchar();
getchar();
return 0;
}
I see that the first 3 replies are totally wrong, to correct those and defend the post below those three (guestgulkan):
The size of the array in elements is MAX, in other words, the array contains MAX number of elements.
A char can hold 256 different values, so you may say that the size is MAX * 8 bits = MAX bytes.
If you want to know how much space in memory s1 will hold for your elements, you can use the following snippet:
int size = sizeof(char) * MAX;
Where size will hold the value that represents the number of bytes.
Do not think a char as a value that holds 1 byte of memory, it may be 4 bytes on an other compiler/os.