Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #340 Last character of string

Assign to c the value of the last character of the string s.

Explain the type of c, and what happens if s is empty.

Make sure to properly handle multi-bytes characters.

char c = s[^1];

New implementation...
< >
programming-idioms.org