// 1. The following program displays welcome
#include <stdio.h>
void main()
{
char *p = calloc(100, 1);
p = "welcome";
printf("%s\n", p);
}
// 2. the following memory allocation program displays 0
#include <stdio.h>
struct p
{
struct p *next;
int x;
};
int main()
{
struct p *p1 = calloc(1, sizeof(struct p));
p1->x = 1;
p1->next = calloc(1, sizeof(struct p));
printf("%d\n", p1->next->x);
return 0;
}
#include <stdio.h>
void main()
{
char *p = calloc(100, 1);
p = "welcome";
printf("%s\n", p);
}
// 2. the following memory allocation program displays 0
#include <stdio.h>
struct p
{
struct p *next;
int x;
};
int main()
{
struct p *p1 = calloc(1, sizeof(struct p));
p1->x = 1;
p1->next = calloc(1, sizeof(struct p));
printf("%d\n", p1->next->x);
return 0;
}
No comments:
Post a Comment