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

Saki said:   1 decade ago
Here declaration of a variable must be done by using predefined and user defined datatypes as void is also a predefined data type also we cannot use it here which it does not allocates any memory during declaration of variable.

ex: int a=0;

int i=0; these statements can be correct.

Shantanu said:   1 decade ago
While initializing the variable requires a valid data type. void is return type not a data type.

Vijay kumar said:   1 decade ago
Void mean empty or NULL value. So void keyword cannot use variable declaration in C.

Lokesh sharma said:   1 decade ago
It is void keyword which do not return any value.

Yusuf MJ said:   1 decade ago
No data type is there to 'v' here.

Void is not a data type to be assigned to any variable.

Shiva Keerthi said:   1 decade ago
Void is not a "data type". Its a result type or a "side effect" of a function. Result type again need not be always binary, like true or false, it can be interpreted as having some result or having no result. About void pointers. They cannot be deference since void pointers indicate the absence of type and also pointer arithmetic is not possible since "data" can not be determined. !

Srinivas said:   1 decade ago
void is an predefined data type, void means nothing.

So we can't define variables for void.

R.Harish said:   1 decade ago
void is not an data type.

void does not return any value.

Rahini said:   1 decade ago
Variable is not assigned in void, only pointer variable is declared.

Pushpa Rz said:   1 decade ago
void can be used for functions and pointers. Similarly variable can be declared void as well.

like void v;

A variable that is itself declared void (such as v) is useless, it cannot be assigned a value, cannot be cast to another type as pointer, infact, cannot be used in any way i.e useless.


Post your comments here:

Your comments will be displayed after verification.