I dont know much about c++ but hasnt it all got to be on seperate lines
i need alittle help with this code
i get this errorCode:#include <iostream> using namespace std; void main() { char c = 'a'; char *ptr = &c; cout << (int)&c <<endl; cout << (int)*ptr <<endl; c= 'b'; *ptr = 'd'; cout << 'c' << endl; }
i was following a tut from 3d buzz but they used visual c++ 03 i have the 05 version i dont no if that will make it not work thanks for the helpCode:: warning C4311: 'type cast' : pointer truncation from 'char *__w64 ' to 'int' Compiling manifest to resources... Linking...
I dont know much about c++ but hasnt it all got to be on seperate lines
PSN ID: splodger15
it probably is splodger, last time i tried using the 'code' tags it put it as a block of code rather than seperate lines
Looks like your warning is coming from the fact that your are using a 64 bit machine whereas the tutorial was probably originally written for a 32 bit machine.
On your machine the character pointer is 64 bits and the int is still 32 bits, so to get rid of the message cast the pointer to a long int instead of just an int.
cout << (long int)&c <<endl;
Now as for the tutorial in general, I question some of it...maybe it gets built upon to explain things further...
char c = 'a';
char *ptr = &c;
cout << (int)&c <<endl;
/*why are they casting the below to an int? This is the data the pointer actually points to...so they are casting a char to an int...so you get the integer representation of 'a'...take off the typecast and you get 'a' printing out, which makes more sense to me. But like I said, maybe they expound on this and change it later or something...*/
cout << (int)*ptr <<endl;
c= 'b';
*ptr = 'd';
/*And here, this just prints out 'c'. Is this a typo? Anyway remove the quotes to get it to print the value of the variable c which at this time is 'd'.*/
cout << 'c' << endl;
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks