Is void a data type in C?

前端 未结 3 625
既然无缘
既然无缘 2020-11-29 22:28

Is void a data type in the C programming language? If so, what type of values can it store? If we have int, float, char,

3条回答
  •  时光说笑
    2020-11-29 22:43

    Void is considered a data type (for organizational purposes), but it is basically a keyword to use as a placeholder where you would put a data type, to represent "no data".

    Hence, you can declare a routine which does not return a value as:

    void MyRoutine();
    

    But, you cannot declare a variable like this:

    void bad_variable;
    

    However, when used as a pointer, then it has a different meaning:

    void* vague_pointer;
    

    This declares a pointer, but without specifying which data type it is pointing to.

提交回复
热议问题