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 7 of 17.
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;
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.
Pavani said:
1 decade ago
Void is the data type used to declare pointer type variables but not the ordinary varibles..
eg
void *p; //correct
void p//not applicable
eg
void *p; //correct
void p//not applicable
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.
XYZ said:
9 years ago
The void is not a data type (both primitive and non-primitive), so declaring variable 'v' with void data type leads to giving an error.
Nithish said:
1 year ago
A void is not exactly a data type, but when you define any function as a void it means that the function returns nothing/no value.
(2)
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?
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.
Ankit said:
1 decade ago
Obviously this is correct question. A variable does not have a return type and void is a return type, so this is syntex error.
Vas krishna said:
1 decade ago
Because void is not a datatype. So syntaticaly its violates the declaration of a variable. So it raises compile time error.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers