Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) char

 

char is a keyword for a (single-)character data type to store a character literal. std::string can be used to store a collection of char.

 

int main()
{
  const char c = 'x';
}

 

Prefer plain char over signed char and unsigned char [1]. Use std::string rather than zero-terminated arrays of chars [2].

 

 

 

 

References

 

  1. Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 6.6. Advice. page 169: '[9] Prefer plain char over signed char and unsigned char'
  2. Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 7.8. Advice. page 199: '[7] Use string rather than zero-terminated arrays of chars'

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict