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.

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.

Abhay said:   1 decade ago
#include<stdio.h>
int main()
{
void *v = 0;

printf("%d", v);

return 0;
}

output: zero

Uttam barik said:   1 decade ago
We declare for variables for user defined or predefined data type. But void is a return type which returns nothing. It not possible to assign a variable to a return type. Becuse we declare variables for datatypes only not for returntype.

Atul said:   1 decade ago
Error: variable or field we is void.

Dharanesh said:   1 decade ago
As we know void is keyword not a datatype. It does return nothing.

Salunkhe amrut said:   1 decade ago
Void is return type we can declare pointer variable to void but not only variable.

Mithilesh Upadhyay said:   1 decade ago
The void is primitive data type in C. The "void" can only used as return type for function definition. It cann't used for variable declaration.

Mukesh Rai said:   1 decade ago
The "void" is used as a data type but we can not use it for variable declaration in 'C'.

Rakesh kumar said:   1 decade ago
In c void means the variable we contains null value, which is not possible.

DevendraSingh said:   1 decade ago
1. void is fundamental data type, which always return null(i.e void).
2. value can not be assigned to void because we cannot assign value to null, as it is already null, so it does not accept
void v = 0;
3. void is used to show return type of function only.


Post your comments here:

Your comments will be displayed after verification.