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.
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.
Najamunnisa begum said:
1 decade 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.
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 #.
Ankit said:
1 decade ago
In simple terms void can not be assigned any value .....
Rohit singh said:
1 decade ago
Void doesnt contain any type of value.
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.
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.
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
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.
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers