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 12 of 17.
Charu said:
1 decade ago
We can declare it as void v; or we can initialize it as int v=0;
If we do both means no meaning.
Moreover, In printf, we used %d which indicates that the variable is of type 'int' and keeps memory for it. But there is no int in declaration. That's the error actually.
If we do both means no meaning.
Moreover, In printf, we used %d which indicates that the variable is of type 'int' and keeps memory for it. But there is no int in declaration. That's the error actually.
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.
Ritesh bhadani said:
1 decade ago
@Sumathi.
int main()
Is a function which is necessary in all C programs, in represents that the main function must return a value of integer type.
int main()
Is a function which is necessary in all C programs, in represents that the main function must return a value of integer type.
Hemant said:
1 decade ago
We cannot declare void variable.
Can only make void pointer.
Can only make void pointer.
Karthick,sairaj said:
1 decade ago
We can't use void for variable declarations. Since void returns NULL values.
Shivani Agarwal said:
1 decade ago
Void is used when a function or anything occupies no space. Here, we are giving variable definition, which should occupy some space. So void cannot be used as datatype for variables which should occupy some space.
Bhagyesh said:
1 decade ago
Void is not using for declaration of variable in c and in oop's language.
Suryakirru said:
1 decade ago
Actually void main means that function does not returns any value to the function but in the question he asked that return 0; That's the error I found.
Gowri said:
1 decade ago
void is a return type specifier. Its does not expect a value. So v=0; is a error.
Saif said:
1 decade ago
Before declaring any variable we have to write its type which is void in this problem and void means nothing that means we didn't declare the variable 'v'.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers