Doubt about dynamic memory allocation
in Programming
42 views
0 votes
0 votes
#include <stdio.h>
#include<stdlib.h>

int main()
{
    int *x=NULL;
    x=(int*)malloc(sizeof(int));
    *x=37;
    free(x);
    int *y=(int*)malloc(sizeof(int));
    *y=40;
    printf("%d  %d",*y,*x);

    return 0;
}
 

 

Output is 40 40

How this is coming?
in Programming
by
5 points
42 views

2 Comments

are you sure the answer is 40 40? Running it gives 40 0.
0
0
x is free, so again accesing it is, undefined behaviour.
0
0

Please log in or register to answer this question.

Ask
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
Welcome to GATE CSE Doubts, where you can ask questions and receive answers from other members of the community.