Hi all,
In the C tutorial on this site is a lesson on typecasting with the following code:
This didn't compile in my Visual C++ 2008 express edition.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(); }
I tried it again but with declaring x before being used in the for loop and it worked:
Is this due to a change in the way things are formatted since the tutorial was written? Or is the tutorial wrong?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(); }
I have no idea as I'm just learning the very basics for now!
Cheers.



LinkBack URL
About LinkBacks




