const_cast char type : const_cast « Data Types « C++ Tutorial






#include <iostream>
using std::cout;
using std::endl;

#include <cstring>
#include <cctype>

const char *maximum( const char *first, const char *second )
{
   return ( strcmp( first, second ) >= 0 ? first : second );
}

int main()
{
   char s1[] = "h";
   char s2[] = "g";

   char *maxPtr = const_cast< char * >( maximum( s1, s2 ) );

   cout << "The larger string is: " << maxPtr << endl;

   return 0;
   
}
The larger string is: h








2.31.const_cast
2.31.1.const_cast int value
2.31.2.const_cast char type
2.31.3.Use const_cast on a const reference
2.31.4.Use const_cast to cast parameter before passing it into a function
2.31.5.Cast parameter with const_cast