Friday, October 15, 2010

Memory Reference Problem

/*
* StruMem.c
*
* Created on: Oct 15, 2010
* Author: KArthikeyan.D
*
*/
# include <stdio.h>
# include <malloc.h>
# include <string.h>
typedef struct struture1
{
int a;
int b;

}stru;

int main()
{
stru *Memory = (stru*)malloc(sizeof(stru));
//Memory = NULL;

Memory->a=12;
Memory->b = 21;

free(Memory);
printf("%d ",Memory->b);
return 0;
}

Note: View last two lines. Memory freed . After that we are trying to get the value.

OutPut: Garbage value

No comments:

Post a Comment