What this fuction returns | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What this fuction returns

struct cube *create_cube(void) { return (struct cube *) calloc(1, sizeof(struct cube)); } main(){ cube = create_cube(); }

1st Jan 2019, 6:16 PM
Hamdan Farooq
Hamdan Farooq - avatar
4 Answers
+ 2
It seems the function returns a pointer to a cube structure, casted from what was initially a void pointer allocated by calloc(), the size of memory allocated was enough to fit the size of one cube structure, the cube structure definition however, is non present. The main method is missing its return type, and inside it, the type of <cube> is undefined, could be it was declared somewhere else, but initialized in main. Hth, cmiiw
1st Jan 2019, 10:43 PM
Ipang
+ 1
I don't know about this thanks for pointing this
1st Jan 2019, 7:53 PM
Hamdan Farooq
Hamdan Farooq - avatar
0
thanks
2nd Jan 2019, 6:33 AM
Hamdan Farooq
Hamdan Farooq - avatar
0
could you give me an example of this
2nd Jan 2019, 6:36 AM
Hamdan Farooq
Hamdan Farooq - avatar