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 8 of 17.
Ankit said:
1 decade ago
Obviously this is correct question. A variable does not have a return type and void is a return type, so this is syntex error.
Vas krishna said:
1 decade ago
Because void is not a datatype. So syntaticaly its violates the declaration of a variable. So it raises compile time error.
Prathyu said:
1 decade ago
We couldn't use &v in printf. We use that symbol for taking input from user in scanf statement not in printf statement.
Deepu said:
2 decades ago
void is a primary data type. We are using variable name of void type and intialized as zero then what is wrong in that?
Tdk said:
5 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)
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
Ketan said:
9 years ago
The void is data type but its initialize with NULL value so no one can change or assign a value to the null variable.
Lalita kumari said:
1 decade ago
If a variable is void and when it is printed with any datatype it accept the size and data type. So how it is wrong?
Jagjit said:
10 years ago
Well you can't declare any variable as void, but you can declare pointers as void thats why we are getting error.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers