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

Kunal Chatterjee said:   9 years ago
The error is shown as in any variable declaration it is actually an indication to the compiler about the type and size of the variable.

For eg : In the statement int a; the compiler determines that when a will be defined we need to allot 2 bytes to it.

But for avoiding data type it cannot assign determine the type & the size of memory to be allocated. Hence, an error is reported.

Manish said:   9 years ago
Void means empty so nothing should get returned, that it must not have any value.

Kareem Maghawry said:   9 years ago
We never use void for declaration variables because void means nothing, so if we used void in the variable that means no variable existing and this not related to c language. But we use void in function argument declaration.

XYZ said:   9 years ago
The void is not a data type (both primitive and non-primitive), so declaring variable 'v' with void data type leads to giving an error.

Hetram Lakhera said:   9 years ago
Hello, all.

We can not assign the value of the pointer.
but void *p;p=0;
int *i;i=0; is valid but p=1, p=9, p=67 and i=12, i=4 is not valid why?

Raviteja said:   10 years ago
It's can't void as main.

Dharani Reddy said:   10 years ago
Void means null. It returns nothing.

Keyur vyas said:   10 years ago
It's not possible,

Because of we never declare or initialize this kind of variable using void.

Ashitosh m n said:   10 years ago
We not declare or initialize a variable using void.

It is not possible.

Lalita kumari said:   10 years ago
If a variable is void and when it is printed with any datatype it accept the size and data type. So how it is wrong?


Post your comments here:

Your comments will be displayed after verification.