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 14 of 17.
Shakil Chand said:
1 decade ago
Void means empty (or nthing) so we use void main () function intialy in any program whcih means we don't return any value because it is void, but if we use int main() than we have to use 'return 0' .
So void can not be used.
So void can not be used.
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.
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.
Venky said:
1 decade ago
void *p;
Here it allocates the chunk of bytes memory and compiler doesn't know how to use this memory.
You can use this memory by using malloc() OR calloc() functions with proper typecasting.
p=(int*)(malloc(sizeof(int));
Now it occupies the memeory 2bytes for every int values.
Here it allocates the chunk of bytes memory and compiler doesn't know how to use this memory.
You can use this memory by using malloc() OR calloc() functions with proper typecasting.
p=(int*)(malloc(sizeof(int));
Now it occupies the memeory 2bytes for every int values.
Madhu said:
1 decade ago
2 errors will occur they were
*value of type void is not allowed
*size of "V" is not know
*value of type void is not allowed
*size of "V" is not know
Sonia said:
1 decade ago
We can't create a void datatype variable, we can only create a void type pointer so that it can be assign to any other typr of pointer.
Pallavee said:
1 decade ago
1) void is a special kind of data type. It can be used only with functions ie as a return value for a function.
2) void is a keyword in C.
2) void is a keyword in C.
Rohit singh said:
1 decade ago
Void doesnt contain any type of value.
Ankit said:
1 decade ago
In simple terms void can not be assigned any value .....
Manish NIITian said:
1 decade ago
Void is return type keyword, so it can't be used as like datatype in c, C++ and C #.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers