I want to know, how the value is printed for the below items. because i set the structure variable one to 0 using memset. but this variable is assigned in mainst.subst using init() method.
printf("\n %d",mainst.subst.t1); printf("\n %d",mainst.subst.t2);
Please kindly let me any one know why its print like that.
Source Code:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct one *oneptr;
struct one
{
char t1;
char t2;
char *path;
};
typedef struct one one_st;
struct char_ar
{
int a;
char b;
one_st subst;
}mainst;
void init(oneptr cp)
{
mainst.a=10;
mainst.b='u';
mainst.subst=*cp;
}
void main()
{
oneptr ptr;
struct one o;
o.t1='t';
o.t2='u';
o.path = malloc(10);
strcpy(o.path,"HI");
init( &o);
ptr = &o;
free(ptr->path);
ptr->path=(char *)NULL;
memset ((char *)ptr, 0, sizeof(one_st));
printf("\n %d",mainst.subst.t1);
printf("\n %d",mainst.subst.t2);
printf("\n %s",mainst.subst.path);
}