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

Asritha said:   8 years ago
The void data type is used to hold any type of variable, provided that it should be typecasted.

Here the void variable is holding int value and it's not declared/typecasted hence the compiler doesn't know what type it is and hence it raises an error.

ISRO said:   8 years ago
Every variable needs storage in memory for storing values. Here Datatype in null, means it will not store any value. Thank you.

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

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.

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

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

Abd said:   7 years ago
@All.

You cannot declare a variable of type void.

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.

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

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


Post your comments here:

Your comments will be displayed after verification.