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 5 of 17.
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:
2 decades 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.
Najamunnisa begum said:
2 decades ago
When we declare the variable memory will not be allocated but when we initialize we need memory to store that variable value.
Since, void is not a data type it results in error.
Since, void is not a data type it results in error.
Georgekutty george said:
1 decade ago
'void' is primary data type. So we can create void data.
But in the case of variable. It is used to store value. Using void in variable is meaningless. So we got the error. !
But in the case of variable. It is used to store value. Using void in variable is meaningless. So we got the error. !
Arpita Baheti said:
1 decade ago
For declaration of any variable required datatype variable
That is
Ex int v=0;
void is a return type not a datatype,
Therefore in this program, void v=0;.
Generates an error.
That is
Ex int v=0;
void is a return type not a datatype,
Therefore in this program, void v=0;.
Generates an error.
Panchanan said:
1 decade ago
When we return a data into void type type cast most be need & assign the value into another variable. Void means nothing we cant assign any value into the void type.
119 said:
1 decade ago
Void is special kind of data type which is only built for functions return type (where no value is returned). So we cannot use this for any kind of variable declaration.
Venkat said:
8 years ago
void is a datatype but the compiler does not allocate memory for that one.
The sizeof(void) it gives 1 byte.but memory not allocated so variable not declared with void.
The sizeof(void) it gives 1 byte.but memory not allocated so variable not declared with void.
Dany said:
2 decades ago
We cant declare variable as a void in c..........It is valid for function.......IF WE use pointer then we can use (void*) as a datatype known as generic pointer....
Yogeshwar Singh said:
1 decade ago
For Void there is no memory size defined for eg in 'int' data type the size is 2 byte, but for void it is not defined so we can not assign any value to void type.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers