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;
}
Discussion:
165 comments Page 9 of 17.
Karthi said:
1 decade ago
The output of this program will return some error in
Line 4: error: variable or field 'v' declared void...
Line 4: error: variable or field 'v' declared void...
Vishwa said:
1 decade ago
In GCC it shows like this.
In function \'main\':
Error: variable or field \'v\' declared void.
void v=0;
In function \'main\':
Error: variable or field \'v\' declared void.
void v=0;
Vivek Tutika said:
3 years ago
Since void is the data type of variable 'v', initialisation of we as 0 (v=0) leads to redeclaration of 'v'.
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.
Ritesh bhadani said:
1 decade ago
Here void represents that v may take any data type, so c compiler will be dangled regarding variable v.
DATTA BACHATE said:
1 decade ago
First convert this void type pointer to basic data types then we can implement it as normal variable.
Lohija said:
1 decade ago
One should not declare as the datatype because the void data type can be used for pointer variables.
Madhu said:
1 decade ago
2 errors will occur they were
*value of type void is not allowed
*size of "V" is not know
*value of type void is not allowed
*size of "V" is not know
Mukesh Rai said:
1 decade ago
The "void" is used as a data type but we can not use it for 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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers