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.

Shalini k said:   1 decade ago
void doesn't return anything so instead of void if int is declared we get the result as 0.

Vinay Singh & Pannelal Goswami said:   1 decade ago
"Void" is no return type keyword for function use, not use in variable declaration.

Keya said:   1 decade ago
Void is prototype so we can not initialize variable.

Vishwa said:   1 decade ago
In GCC it shows like this.

In function \'main\':

Error: variable or field \'v\' declared void.

void v=0;

Jayaprakash said:   1 decade ago
Void means null and we usually used to declare the return type in functions. Variable declaration usually allocates memory to the variable.

Void keyword cannot assign any memory to the variable and hence it cannot be used for variable declaration.

Saif said:   1 decade ago
Before declaring any variable we have to write its type which is void in this problem and void means nothing that means we didn't declare the variable 'v'.

Gowri said:   1 decade ago
void is a return type specifier. Its does not expect a value. So v=0; is a error.

Suryakirru said:   1 decade ago
Actually void main means that function does not returns any value to the function but in the question he asked that return 0; That's the error I found.

Bhagyesh said:   1 decade ago
Void is not using for declaration of variable in c and in oop's language.

Shivani Agarwal said:   1 decade ago
Void is used when a function or anything occupies no space. Here, we are giving variable definition, which should occupy some space. So void cannot be used as datatype for variables which should occupy some space.


Post your comments here:

Your comments will be displayed after verification.