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 16 of 17.
Abd said:
7 years ago
@All.
You cannot declare a variable of type void.
You cannot declare a variable of type void.
Hemanth kumar.v said:
7 years ago
Actually, In this program, variable we is defined with void, at the time of compiling compiler will not able to allocated memory for that variable, because datatype of variable we is not given, so, error is thrown by compiler.
Thank you.
Thank you.
Hari krishna said:
7 years ago
Here, the void is in pointer when we use void, convert (typecasting) into a desired data type.
Shashank patchalla said:
7 years ago
@All.
As per my knowledge; It is
#include<stdio.h>
int main()
{
void v = 0;
printf("%d", v);//* the address is not allocated so it's a very easy but somewhat difficult to crack ok *//
return 0;
}
As per my knowledge; It is
#include<stdio.h>
int main()
{
void v = 0;
printf("%d", v);//* the address is not allocated so it's a very easy but somewhat difficult to crack ok *//
return 0;
}
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.
Dipak said:
5 years ago
Void is keyword in c so that we can't use it for variable name.
(2)
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.
C G said:
4 years ago
Here they use the format specifier as %d but it is not mentioned that V is an integer. Anyone, explain this in detail.
(1)
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers