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

Atul ANAND said:   1 decade ago
It is very simple, but first lets get one thing straight that YES void is a PRIMARY datatype.

We can use void pointer because size of pointer does not depend on datatype, when you have to access your data using void pointer then you have to typecast.

When we use void variable the size of variable is unknown.

So this part is tricky as the compiler doesn't know how much memory it needs to store this variable.

Umesh kumar said:   1 decade ago
void v=0;

In this statement, v is assigned the value 0 which is a integer value and the void type is used to declare it. Both doesnot match, so, its a error.

Rohan said:   1 decade ago
We can't use void to declare the variables in c because void is a derived data type.

Chaitu said:   1 decade ago
Unlike other primitive data types in c, void data type does not create any variable but returns an empty set of values. Thus, we can say that it stores null.

I guess there is an error in the above program i.e., the 'A'.

Since it should not be given an integer value since it is having a null. ,

ROSHAN MAHAJAN said:   1 decade ago
We can't used void with variables declaration. Because it is derived data type and is used for Function.

Rachna said:   1 decade ago
void should not be written here. Only this is the syntax error, otherwise it is correct. void just used for return statement and not in front of declaration.

Vinit VJ said:   1 decade ago
void is like a 'general type' which contains nothing nor can be given/return but we can cast the variable of void type to other data type! thus we can make the same variable in exists which contains a 'memory'.

In short a data type except 'void', returns a memory space to variable in program to make it alive.

Mamatha said:   1 decade ago
Void does not contain any return value.

Srividhya said:   1 decade ago
void does not return anything.

Nkv said:   1 decade ago
void does not have return type.


Post your comments here:

Your comments will be displayed after verification.