C Programming - Declarations and Initializations - Discussion

Discussion Forum : Declarations and Initializations - Point Out Errors (Q.No. 2)
2.
Point out the error in the following program.
#include<stdio.h>
int main()
{
    void v = 0;

    printf("%d", v);

    return 0;
}
Error: Declaration syntax error 'v' (or) Size of v is unknown or zero.
Program terminates abnormally.
No error.
None of these.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
165 comments Page 9 of 17.

Nitish Patil said:   1 decade ago
Since "void" is a primary data type, I believe we can create a variable of its type, but in printf statement there is a effort made in displaying the variable as an integer so just typecasting it to int would have made the code work.

Correct me, if I am wrong.

SkYlAr said:   1 decade ago
Whenever you are declaring a void variable, it means that you are saying to compiler that memory requirements to store that variable is unknown, so when you will for printing it then compiler will never know up-to how much bytes of memory location it have to fetch the data and will give error.

Pushpa Rz said:   1 decade ago
void can be used for functions and pointers. Similarly variable can be declared void as well.

like void v;

A variable that is itself declared void (such as v) is useless, it cannot be assigned a value, cannot be cast to another type as pointer, infact, cannot be used in any way i.e useless.

Rahini said:   1 decade ago
Variable is not assigned in void, only pointer variable is declared.

R.Harish said:   1 decade ago
void is not an data type.

void does not return any value.

Srinivas said:   1 decade ago
void is an predefined data type, void means nothing.

So we can't define variables for void.

Shiva Keerthi said:   1 decade ago
Void is not a "data type". Its a result type or a "side effect" of a function. Result type again need not be always binary, like true or false, it can be interpreted as having some result or having no result. About void pointers. They cannot be deference since void pointers indicate the absence of type and also pointer arithmetic is not possible since "data" can not be determined. !

Yusuf MJ said:   1 decade ago
No data type is there to 'v' here.

Void is not a data type to be assigned to any variable.

Lokesh sharma said:   1 decade ago
It is void keyword which do not return any value.

Vijay kumar said:   1 decade ago
Void mean empty or NULL value. So void keyword cannot use variable declaration in C.


Post your comments here:

Your comments will be displayed after verification.