C Typecasting

Typecasting is a way to make a variable of one type, such as an int, act like another type, such as a char, for one single operation. To typecast something, simply put the type of variable you want the actual variable to act as inside parentheses in front of the actual variable.

Example 1

#include <stdio.h>
#include <stdlib.h>
 
int main()
{
 
  /* The (char) is a typecast, telling the computer to interpret the 65 as a
     character, not as a number.  It is going to give the character output of 
     the equivalent of the number 65 (It should be the letter A for ASCII).
     Note that the %c below is the format code for printing a single character
   */
  printf( "%c\n", (char)65 );
 
    getchar();
}

Any Comments about this page

Your name
Email
Extra comments
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.