A c-string ends with a null character. Your loop should be adding 1 to a total for each character until it finds that zero char.
see the tutorial page, http://www.cplusplus.com/doc/tutorial/ntcs/
Don't do the cout inside your function, instead return the total.
#include <iostream>
usingnamespace std;
int myStrLength(char *);
int main()
{
char str[10] = {"Hello"};
int len = myStrLength(str);
cout << "STR length " << len << endl;
}
int myStrLength(char *str)
{
int size = 0;
// Loop until a character '\0' is found
for ( int i = 0; str[i] != '\0' ; i++)
{
size++;
}
return size;
}