EmbLogic's Blog

Nested Structures Ft. Pointer

#include<stdio.h>
#include<stdlib.h>

struct disfeet
{
int *f;

};

struct distance
{
struct disfeet *d;
};

int main()
{
struct distance *d1;

d1=(struct distance *)malloc(sizeof(struct distance));
d1->d=(struct disfeet *)malloc(sizeof(struct disfeet));
d1->d->f=(int *)malloc(sizeof(int));

printf(“enter distance\n”);
scanf(“%d”,&d1->d->f);

printf(“distance is %d feet.\n\n”,d1->d->f);

return 0;

}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>