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 5 of 17.

Najamunnisa begum said:   1 decade ago
When we declare the variable memory will not be allocated but when we initialize we need memory to store that variable value.

Since, void is not a data type it results in error.

Georgekutty george said:   1 decade ago
'void' is primary data type. So we can create void data.

But in the case of variable. It is used to store value. Using void in variable is meaningless. So we got the error. !

Arpita Baheti said:   1 decade ago
For declaration of any variable required datatype variable
That is
Ex int v=0;
void is a return type not a datatype,
Therefore in this program, void v=0;.
Generates an error.

Panchanan said:   1 decade ago
When we return a data into void type type cast most be need & assign the value into another variable. Void means nothing we cant assign any value into the void type.

119 said:   1 decade ago
Void is special kind of data type which is only built for functions return type (where no value is returned). So we cannot use this for any kind of variable declaration.

Venkat said:   7 years ago
void is a datatype but the compiler does not allocate memory for that one.

The sizeof(void) it gives 1 byte.but memory not allocated so variable not declared with void.

Dany said:   1 decade ago
We cant declare variable as a void in c..........It is valid for function.......IF WE use pointer then we can use (void*) as a datatype known as generic pointer....

Yogeshwar Singh said:   1 decade ago
For Void there is no memory size defined for eg in 'int' data type the size is 2 byte, but for void it is not defined so we can not assign any value to void type.

Kishor patil said:   1 decade ago
Variable should not be a void type. It is not a valid type for variables.

We can only use it for functions.

Void in programming language means it does nothing.

Nandan said:   1 decade ago
A variable must have some space (size of variable) to store some value in it. Void has no size and thus a variable declared as void can't store any value in it.


Post your comments here:

Your comments will be displayed after verification.