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:
168 comments Page 13 of 17.
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'.
Mithilesh Upadhyay said:
1 decade ago
The void is primitive data type in C. The "void" can only used as return type for function definition. It cann't used for variable declaration.
Salunkhe amrut said:
1 decade ago
Void is return type we can declare pointer variable to void but not only variable.
Dharanesh said:
1 decade ago
As we know void is keyword not a datatype. It does return nothing.
Atul said:
1 decade ago
Error: variable or field we is void.
Uttam barik said:
1 decade ago
We declare for variables for user defined or predefined data type. But void is a return type which returns nothing. It not possible to assign a variable to a return type. Becuse we declare variables for datatypes only not for returntype.
Abhay said:
1 decade ago
#include<stdio.h>
int main()
{
void *v = 0;
printf("%d", v);
return 0;
}
output: zero
int main()
{
void *v = 0;
printf("%d", v);
return 0;
}
output: zero
Nandan said:
1 decade ago
A variable must have some space (size of variable) to store some value in it. Void has no size and thus a variable declared as void can't store any value in it.
SuryaMaruti said:
1 decade ago
I think void is not variable define datatype.
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...
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers