Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. #include<stdio.h>
  2. //#include<stdlib.h> --> When this include is not commented out, after build, you will get Warning C4013 'malloc' undefined; assuming extern returning int. In Win10 64bit, this will cause bad malloc behaviour and crash due to access violation.
  3.  
  4. struct MyStruct{
  5. int a;
  6. };
  7.  
  8. int main() {
  9. struct MyStruct *m = (struct MyStruct*)(malloc(sizeof(struct MyStruct)));
  10. m->a = 5; //will crash due to access violation at this line.
  11. printf("m->a = %d\nPress Enter...\n", m->a);
  12. getchar();
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement