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

Mohini said:   1 decade ago
Void is a primitive data type but it declaration of variable using void is wrong!thats it.

HEMALATHA said:   1 decade ago
What is the format specifier for 'void'?

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.

BaBa said:   1 decade ago
Only function and pointer can be declare as void not variable.

Devi said:   1 decade ago
Void is a data type and we can use it at any time.

Devanshmody said:   1 decade ago
Data type should be of int or one can use typedef function.

Panchanan said:   1 decade ago
Void is an generic pointer which contain any type of data. But it's size is unknown value. Before assign the void pointer value you must type converted into the required one.

void v;
int b;
b=(int)v;

Divya said:   1 decade ago
Void returns only zero.
We cannot use it like data type only use return type.

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.

Sunil Kumar(S.K) said:   1 decade ago
Only pointer can be void not a variable.


Post your comments here:

Your comments will be displayed after verification.