Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

what happens if i acess a freed variable in c

#include <cs50.h>
#include <stdio.h>

int main(void)
{
  {
    int* px = malloc(sizeof(int));
    *px = 3;
    printf("&px = %i, px = %p
", *px, px);


    free(px);

    if( px == NULL)
        printf("px is null after free
");
    else
        printf(" px = %p
",px);
   }
//     this printf would demonstrate that px is out of scope.
//            printf(" px = %p
",px);
}
Source by cs50.stackexchange.com #
 
PREVIOUS NEXT
Tagged: #acess #freed #variable
ADD COMMENT
Topic
Name
5+4 =