Hi all,
In the C tutorial on this site is a lesson on typecasting with the following code:
Code:
#include <stdio.h>
int main()
{
for ( int x = 0; x < 256; x++ ) {
/* Note the use of the int version of x to output a number and the use
* of (char) to typecast the x into a character which outputs the
* ASCII character that corresponds to the current number
*/
printf( "%d = %c\n", x, (char)x );
}
getchar();
}
This didn't compile in my Visual C++ 2008 express edition.
I tried it again but with declaring x before being used in the for loop and it worked:
Code:
#include <stdio.h>
int x;
int main()
{
for ( x = 0; x < 256; x++ ) {
/* Note the use of the int version of x to output a number and the use
* of (char) to typecast the x into a character which outputs the
* ASCII character that corresponds to the current number
*/
printf( "%d = %c\n", x, (char)x );
}
getchar();
}
Is this due to a change in the way things are formatted since the tutorial was written? Or is the tutorial wrong?
I have no idea as I'm just learning the very basics for now!
Cheers.