CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Created by Nariman Tajari
#include <iostream>
#include <cstring>
//keep in mind that structs
//can have padding from the compiler
//so this is not safe, you would have
//to do additional checks
struct st {
char ch;
};
int main() {
st s1{ 'c' };
st s2{ s1 };
char c1;
char c2;
//basically casting them with memcpy:
memcpy(&c1, &s1, 1);
memcpy(&c2, &s2, 1);
//does the same as:
//auto c1{ reinterpret_cast<char>(s1) };
//auto c2{ reinterpret_cast<char>(s2) };
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run