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

Lohija said:   1 decade ago
One should not declare as the datatype because the void data type can be used for pointer variables.

Mass said:   1 decade ago
In printf statement we should have ambesend symbol as &v.

Karthi said:   1 decade ago
Void is a return type. It cannot be assigned for variables.

Arjun Reddy said:   1 decade ago
Void is not a datatype.

It is a keyword.

Prathik said:   1 decade ago
Void can be used as int, char so what is the error in the above program.

Gertin samules said:   1 decade ago
void datatype wont allocate any memory so if void type means nothing but void* makes sense when sending generic type of data to functions and they act like generic pointers which can be converted to other types..

Nithin said:   1 decade ago
void is a return type and variable should not declare to it.

Shashi bhushan vishwakarma said:   1 decade ago
1. Size of 'v' is unknown or zero
2. Value of type is not allowed in this statement- printf("%d",v);

Jyothi said:   1 decade ago
Void means which not return any thing. If you put void in front of main function means that is not return any thing.

So, void should not be used for declaring the variable data types otherwise it shows error.

Deepu said:   1 decade ago
void is a primary data type. We are using variable name of void type and intialized as zero then what is wrong in that?


Post your comments here:

Your comments will be displayed after verification.