Return end of char *

closed account (2NywAqkS)
Simple question. How would you return a pointer to the end of a character array?

e.g. "Hello, World" would return 'd'

Thanks,
Rowan.
1
2
const char* str = "Hello, World";
const char* lastChar = str + std::strlen(str) - 1;

1
2
3
4
5
char* returnLastChar (char* p)
{
  while(*(p+1)!=0) ++p;
  return p;
}
closed account (2NywAqkS)
Thanks, perfect!
Topic archived. No new replies allowed.