Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int main(){
- char *p = NULL; //empty pointer
- if (p) // evaluates to false as the pointer points to nothing
- std::cout <<"This won't get displayed!\n";
- p = new char[50];//allocate some memory
- if (p) {//memory has been allocated so this test will pass
- for (unsigned char i = 0; i != 50; i++) {
- char &v = *(p + i); // create a reference to
- v = 75; // set the character to K
- }
- // print out those K's
- for (unsigned char i = 0; i != 50; i++)
- std::cout <<*(p + i);
- // de-allocate the memory
- delete[] p;
- std::cout <<"\n";
- // apparently doesn't delete it all
- for(size_t i = 0; i != 50; i++)
- std::cout <<*(p + i);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement