Discussion: Typecasting an Array
In the previous quiz, C++ online test, we tested our experience gained from the course.
2 messages from 2 displayed.
//= Settings::TRACKING_CODE_B ?> //= Settings::TRACKING_CODE ?>
In the previous quiz, C++ online test, we tested our experience gained from the course.
#include <iostream>
#include <cstring>
using namespace std;
int main() {
char cbuff[32];
short* sbuff = reinterpret_cast<short*>(&cbuff[0]); // use reinterpret_cast for type punning
sbuff[10] = 65;
cout << static_cast<int>(cbuff[20]); // cast the char to an int to print it correctly
cin.get();
return 0;
}
Try this, hope this will help you, or you can choose a different compiler to run the code. I found this post on the internet; here author listed many cpp compiler, choose any online compiler and run the code.
2 messages from 2 displayed.