Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int x = 1;
- char c = *((char*)&x);
- int x = 1;
- char c = *((char*)&x);
- MyClass x; // object of MyClass
- MyClass *x; // pointer to an object of MyClass - the actual value is undefined and trying to access it will most likely result in an access violation (due to reading somewhere random).
- MyClass *x = 0; // same as above, but now the default value is defined and you're able to detect whether it's been set (accessing it would essentially be a "null reference exception"; but it's actually a null pointer).
- MyClass &x = MyClass(); // creating a new reference pointing to an existing object. This would be Java's "MyClass x = new MyClass();"
- int x = 1;
- char c = (char) x; // Lose precision
- int x = 1;
- char *c = (char *)x;
- char *c;
- c = 1; // Set the address of c to 0x0000000000000001
- #define PIC_LOC 0x1000
- #define PIC_ENABLE_PORT *((char*)(PIC_LOC+0x10))
- #define BIT_ENABLE (1 << 3)
- ...
- PIC_ENABLE_PORT |= BIT_ENABLE;
- ...
- // 1a: promote int to double to get the correct type of division
- int numerator = rand(), denominator = rand();
- double d = double(numerator) / double(denominator);
- // 1b: convert int to double to achieve a particular argument deduction
- int n;
- template <typename T> void do_numeric_stuff(T x) { /* ... */ }
- do_numeric_stuff(double(n));
- struct B { }; struct D : B { };
- D x;
- D * p = &x; // pointer to x
- B * q = p; // implicit conversion; may change the value!
- std::ofstream file("output.bin"); // output file
- char large_buffer[HUGE]; // in-memory buffer
- unsigned int n = get_data();
- char const * p = reinterpret_cast<char const *>(&n);
- file.write(p, p + sizeof n); // write the bytes of `n`
- std::copy(p, p + sizeof n, large_buffer); // ditto
- std::copy(large_buffer + 17, large_buffer + 17 + sizeof n,
- reinterpret_cast<char *>(&n)); // repopulate `n` from buffer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement