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 17 of 17.
Arul said:
5 years ago
Void is a no return type in function.
Dhruv singh said:
5 years ago
Actually, we can mention the return type of a variable at the time of declaration as well as intilization but in this case it should have return some integer type value. So we can not determine it as void.
Tdk said:
4 years ago
The void is used here as a data type for a memory holder but it doesnt works that way, but it can hold as a void *ptr.
Hari said:
3 years ago
Variable or field 'v' declared void.
Since we declared it as void before using it, we need to typecast the void variable into desired data type so that we can use v and also we can only declare void pointers which we can convert into desired data type which we need in our project.
Since we declared it as void before using it, we need to typecast the void variable into desired data type so that we can use v and also we can only declare void pointers which we can convert into desired data type which we need in our project.
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'.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers