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 4 of 17.
Sai sandeep(Chinna) said:
1 decade ago
Hai,
Void is a primary datatype, but we can not use it for declaring a variable.
A pointer variable declared as a void but not a variable.
Hense, compiler sends the error message as declaration of variable is wrong.
Void is a primary datatype, but we can not use it for declaring a variable.
A pointer variable declared as a void but not a variable.
Hense, compiler sends the error message as declaration of variable is wrong.
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.
Gertin samules said:
1 decade ago
void datatype wont allocate any memory so if void type means nothing but void* makes sense when sending generic type of data to functions and they act like generic pointers which can be converted to other types..
Jyothi said:
1 decade ago
Void means which not return any thing. If you put void in front of main function means that is not return any thing.
So, void should not be used for declaring the variable data types otherwise it shows error.
So, void should not be used for declaring the variable data types otherwise it shows error.
Maragatha veni said:
1 decade ago
In printf statement how it is possible to print the value of 'v', hence we does not have to return anything using void data type, how it is possible to display the output.
This program will get syntax error.
This program will get syntax error.
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.
MOHD JAVED SAIFE said:
1 decade ago
Void is the type of data. That tells to the user that function does not return any value. And here in the program the void is used as a variable so C language does not allow in these kinds of declaration.
Suprava mallick said:
1 decade ago
void can't be a data type, It is a return type which return null so it can't be declare with a variable name.
Ex: void a;// It show u an error.
Pointer variable declared as void. So it gives an error
Ex: void a;// It show u an error.
Pointer variable declared as void. So it gives an error
Panchanan said:
1 decade ago
Void is an generic pointer which contain any type of data. But it's size is unknown value. Before assign the void pointer value you must type converted into the required one.
void v;
int b;
b=(int)v;
void v;
int b;
b=(int)v;
HARIKRISHNAN.P said:
1 decade ago
void is a primitive data type in C.
void, in C has no size. Thus, if you were to declare a variable of type "void", the compiler would not know how much memory to allocate for it.
void, in C has no size. Thus, if you were to declare a variable of type "void", the compiler would not know how much memory to allocate for it.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers