i have following program, have structure. going assign values , write file. confusion here is, have declared pointer structure , has not allocated memory. how variable assignment works? able retrieve values correctly file "/home/info"
#include <stdio.h> #define filee "/home/info" typedef struct my_info { int i; int j; int k; int l; }_my_info; void main() { _my_info *my_info; int fd; file *fp; my_info->i=100; my_info->j=300; my_info->k=200; my_info->l=400; fp = fopen(filee,"w"); if (fp == null) printf("error in opening file\n"); fd=fwrite(my_info, sizeof(_my_info), 1, fp); if (fd<0) printf("error while writing\n"); fclose(fp); }
when declare my_info
_my_info *my_info;
it have undefined value. in case, value of my_info
within range of valid memory addresses ram. write it, , read take place.
however, don't know other memory changing due this. may cause memory corruption, in larger programs.
Comments
Post a Comment