Hi All,
recently i studied one document for difference between structure and union. I that they said, union did not support the dynamic memory allocation and structure should support dynamic memory allocation.
I tried one program with dynamic memory allocation as below
Code:
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
union koti
{
int i;
float f;
char c;
};
int main()
{
union koti *p;
p= (union koti *)malloc(1 * sizeof(union koti));
p->f =12.3;
printf ("%f\n",p->f);
return 0;
}
Am i correct? above program can prove that union will support dynamic memory allocation?
Please correct me if i am wrong.
Thanks in advance.