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

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.

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

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?

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.

Divya said:   1 decade ago
void is not in datatype.

Alok said:   1 decade ago
Void is only used in case of pointers, as void is a keyword and this data type cannot be used to refer a variable.

This is correct void *ptr;

DATTA BACHATE said:   1 decade ago
First convert this void type pointer to basic data types then we can implement it as normal variable.


Post your comments here:

Your comments will be displayed after verification.