Using a non-constant pointer to non-constant data : const pointer « Pointer « C Tutorial






#include <stdio.h>
#include <ctype.h>

void convertToUppercase( char *sPtr ); /* prototype */

int main()
{
   char string[] = "characters and abcde";

   printf( "The string before conversion is: %s", string );
   convertToUppercase( string );
   printf( "\nThe string after conversion is: %s\n", string ); 
          
   return 0;

}

void convertToUppercase( char *sPtr )
{
   while ( *sPtr != '\0' ) {
      if ( islower( *sPtr ) ) {
         *sPtr = toupper( *sPtr );
      }
      ++sPtr;
   } 
}
The string before conversion is: characters and abcde
The string after conversion is: CHARACTERS AND ABCDE








10.9.const pointer
10.9.1.Attempting to modify a constant pointer to non-constant data
10.9.2.Attempting to modify data through a non-constant pointer to constant data.
10.9.3.Using a non-constant pointer to non-constant data
10.9.4.A non-constant pointer to constant data