Why not void is a datatype in C? -


this question has answer here:

today 1 student came me , asked me, sir have int, float, char , datatypes in c.

when write int i, means i variable of type integer , on float f , char c.

similarly have int *i means i pointer integer. same float *f , char *c.

and have void* v; in c.

void pointer called generic pointer.

he asked me can have void pointer, why can't have void v (as datatype)?

i speechless. so, requesting pls me. how make him understand.

here's how explain it:

in higher-level languages, variables represent abstract things, , it's language decide how represent them in bits , push bits around act on things. makes sense allow variable represent concept of "nothing".

c not that. c variables actual collections of bits stored in memory. represent programmer. makes no sense c program have variable of type "nothing"--that mean "allocate no bits of memory", , wouldn't know that. in c, "int" means "allocate 32 bits of memory", "int *" means "allocate memory sufficient hold memory address, , when dereference it, 32 bits @ time". "void *" means "allocate memory memory address, , i'll tell later how many bits fetch there".

a "void" function return type in c means "return function, don't pass bits caller". in higher-level language python, example, "return none" means return caller, , pass collection of bits represents abstract concept of 'nothing'", different thing.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -