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 3 of 17.
ISRO said:
8 years ago
Every variable needs storage in memory for storing values. Here Datatype in null, means it will not store any value. Thank you.
Asritha said:
8 years ago
The void data type is used to hold any type of variable, provided that it should be typecasted.
Here the void variable is holding int value and it's not declared/typecasted hence the compiler doesn't know what type it is and hence it raises an error.
Here the void variable is holding int value and it's not declared/typecasted hence the compiler doesn't know what type it is and hence it raises an error.
Sayali said:
8 years ago
void is a return type, not a data type. Hence we can not use it to declare a variable.
Bharath said:
8 years ago
Void itself is a null value. You cannot declare a null value.
Ketan said:
8 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.
Jeratin said:
8 years ago
The void is datatype.
Reema said:
8 years ago
Void is not a keyword.
Farman said:
9 years ago
I think the void variable is a general type if we assign any value to the void data type we must be type cast according to the data which we want to be stored.
Gopi vykuntapu said:
9 years ago
When we are declaring a variable we should provide what type it is that int, char, float, double.
From that compiler arrange memory for that variable, bur void is used in function passing values and return value. If fun returns int type data than we provide an int. If fun returns nothing then we provide void. But in the case of a pointer that pointer may be any type it takes the 4 bytes (in GCC) so that whether it is int, char, float, any it takes 4 bytes. So we can use void pointer variable that can typecast to any data according to our requirement.
From that compiler arrange memory for that variable, bur void is used in function passing values and return value. If fun returns int type data than we provide an int. If fun returns nothing then we provide void. But in the case of a pointer that pointer may be any type it takes the 4 bytes (in GCC) so that whether it is int, char, float, any it takes 4 bytes. So we can use void pointer variable that can typecast to any data according to our requirement.
Jagjit said:
9 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