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.

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.

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

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

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

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.

Maragatha veni said:   1 decade ago
In printf statement how it is possible to print the value of 'v', hence we does not have to return anything using void data type, how it is possible to display the output.

This program will get syntax error.

Shine said:   1 decade ago
What does a null ptr point to? If it is a ptr it should point to some location so is it that nothing is stored at that location?

Hardik said:   1 decade ago
Can not declare like this void is keyword it's not a datatype.

Vishakha said:   1 decade ago
Only pointers can be declared as void not any other variable because pointers are of fixed size so even on being void its allocated space in memory but a normal variable declared as cannot be allocated space in memory and thus gives error.

Kishor patil said:   1 decade ago
Variable should not be a void type. It is not a valid type for variables.

We can only use it for functions.

Void in programming language means it does nothing.


Post your comments here:

Your comments will be displayed after verification.