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:
168 comments Page 7 of 17.
Ritesh bhadani said:
1 decade ago
@Sumathi.
int main()
Is a function which is necessary in all C programs, in represents that the main function must return a value of integer type.
int main()
Is a function which is necessary in all C programs, in represents that the main function must return a value of integer type.
Pramod karale said:
1 decade ago
I think we cant declare variable with void datatype. We can only use void with function or declaring pointer i.e (void*)
So it gives the error.
So it gives the error.
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:
2 decades 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:
2 decades 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:
1 decade 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:
2 years 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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers