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 8 of 17.
Umesh kumar said:
1 decade ago
void v=0;
In this statement, v is assigned the value 0 which is a integer value and the void type is used to declare it. Both doesnot match, so, its a error.
In this statement, v is assigned the value 0 which is a integer value and the void type is used to declare it. Both doesnot match, so, its a error.
Atul ANAND said:
1 decade ago
It is very simple, but first lets get one thing straight that YES void is a PRIMARY datatype.
We can use void pointer because size of pointer does not depend on datatype, when you have to access your data using void pointer then you have to typecast.
When we use void variable the size of variable is unknown.
So this part is tricky as the compiler doesn't know how much memory it needs to store this variable.
We can use void pointer because size of pointer does not depend on datatype, when you have to access your data using void pointer then you have to typecast.
When we use void variable the size of variable is unknown.
So this part is tricky as the compiler doesn't know how much memory it needs to store this variable.
DATTA BACHATE said:
1 decade ago
First convert this void type pointer to basic data types then we can implement it as normal variable.
Alok said:
1 decade ago
Void is only used in case of pointers, as void is a keyword and this data type cannot be used to refer a variable.
This is correct void *ptr;
This is correct void *ptr;
Divya said:
1 decade ago
void is not in datatype.
Kishor patil said:
1 decade ago
Variable should not be a void type. It is not a valid type for variables.
We can only use it for functions.
Void in programming language means it does nothing.
We can only use it for functions.
Void in programming language means it does nothing.
Vishakha said:
1 decade ago
Only pointers can be declared as void not any other variable because pointers are of fixed size so even on being void its allocated space in memory but a normal variable declared as cannot be allocated space in memory and thus gives error.
Hardik said:
1 decade ago
Can not declare like this void is keyword it's not a datatype.
Shine said:
1 decade ago
What does a null ptr point to? If it is a ptr it should point to some location so is it that nothing is stored at that location?
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers