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:
168 comments Page 17 of 17.

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

Jyothi said:   2 decades 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:   2 decades 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?

Ambi said:   2 decades ago
You can never create a void variable. Only Creation of void pointer is possible.

Mohsin said:   2 decades ago
v and *vptr is declared as void pointers and we cannot use v and *vptr until and unless we convert that variables to the desired data type.

Here we are assigning value 0 to v and v doent hold any memory location to assign the value first we have to convert void v to integer type then only we can assing the value to it.

Ex (int) v = 0 ;
or v = (int) 0 ;

Anything I am not sure.

Sandeep said:   2 decades ago
I run it on Dev C IDE then the error variable or field v declared void!

Mymuna said:   2 decades ago
Correct.

Prachi Deshmukh said:   2 decades ago
Is the question correct?

BOth the pointers point to v ?
cptr = &v;
vptr = &v;
Or is it
cptr = &c?


Post your comments here:

Your comments will be displayed after verification.