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

Arul said:   5 years ago
Void is a no return type in function.

Shashank patchalla said:   7 years ago
@All.

As per my knowledge; It is

#include<stdio.h>
int main()
{
void v = 0;

printf("%d", v);//* the address is not allocated so it's a very easy but somewhat difficult to crack ok *//

return 0;
}

Hari krishna said:   7 years ago
Here, the void is in pointer when we use void, convert (typecasting) into a desired data type.

Hemanth kumar.v said:   7 years ago
Actually, In this program, variable we is defined with void, at the time of compiling compiler will not able to allocated memory for that variable, because datatype of variable we is not given, so, error is thrown by compiler.

Thank you.

Abd said:   7 years ago
@All.

You cannot declare a variable of type void.

Shivkumar Hegonde said:   7 years ago
Void is not a valid data type to store the data. It should be void *.
(1)

Jothipriya said:   7 years ago
Void function does not return a value.

Silpa said:   7 years ago
Hi friends, in my view, the void is a primary data type and it (void) means no return value.

Venkat said:   7 years ago
void is a datatype but the compiler does not allocate memory for that one.

The sizeof(void) it gives 1 byte.but memory not allocated so variable not declared with void.

Saurav kumar roy said:   8 years ago
Void is not a keyword, it is a datatype.


Post your comments here:

Your comments will be displayed after verification.