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

Prathyu said:   1 decade ago
We couldn't use &v in printf. We use that symbol for taking input from user in scanf statement not in printf statement.

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?

Tdk said:   4 years ago
The void is used here as a data type for a memory holder but it doesnt works that way, but it can hold as a void *ptr.

C G said:   4 years ago
Here they use the format specifier as %d but it is not mentioned that V is an integer. Anyone, explain this in detail.
(1)

Abhay said:   1 decade ago
#include<stdio.h>
int main()
{
void *v = 0;

printf("%d", v);

return 0;
}

output: zero

Ketan said:   8 years ago
The void is data type but its initialize with NULL value so no one can change or assign a value to the null variable.

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?

Jagjit said:   9 years ago
Well you can't declare any variable as void, but you can declare pointers as void thats why we are getting error.

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?

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);


Post your comments here:

Your comments will be displayed after verification.