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

MOHD JAVED SAIFE said:   1 decade ago
Void is the type of data. That tells to the user that function does not return any value. And here in the program the void is used as a variable so C language does not allow in these kinds of declaration.

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.

Viniya philip said:   1 decade ago
Void is a return type of function not for variable.

Pallavi said:   1 decade ago
We can not define a variable with void type. Only we can define pointer of void type.

Sumathi said:   1 decade ago
What is the meaning of int main(). I can't understand the exact meaning. Please any one help me.

Ishwariya said:   1 decade ago
It is an error because void is not a data type.

Meghana said:   1 decade ago
Size of v is 0, since it is of type void which returns empty value.

Charu said:   1 decade ago
We can declare it as void v; or we can initialize it as int v=0;
If we do both means no meaning.

Moreover, In printf, we used %d which indicates that the variable is of type 'int' and keeps memory for it. But there is no int in declaration. That's the error actually.

Ritesh bhadani said:   1 decade ago
Here void represents that v may take any data type, so c compiler will be dangled regarding variable v.

Ritesh bhadani said:   1 decade ago
@Sumathi.

int main()

Is a function which is necessary in all C programs, in represents that the main function must return a value of integer type.


Post your comments here:

Your comments will be displayed after verification.