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 9 of 17.
Prachi Deshmukh said:
2 decades ago
Is the question correct?
BOth the pointers point to v ?
cptr = &v;
vptr = &v;
Or is it
cptr = &c?
BOth the pointers point to v ?
cptr = &v;
vptr = &v;
Or is it
cptr = &c?
Shashi bhushan vishwakarma said:
2 decades ago
1. Size of 'v' is unknown or zero
2. Value of type is not allowed in this statement- printf("%d",v);
2. Value of type is not allowed in this statement- printf("%d",v);
Karthi said:
1 decade ago
The output of this program will return some error in
Line 4: error: variable or field 'v' declared void...
Line 4: error: variable or field 'v' declared void...
Vishwa said:
1 decade ago
In GCC it shows like this.
In function \'main\':
Error: variable or field \'v\' declared void.
void v=0;
In function \'main\':
Error: variable or field \'v\' declared void.
void v=0;
Vivek Tutika said:
4 years ago
Since void is the data type of variable 'v', initialisation of we as 0 (v=0) leads to redeclaration of 'v'.
ROSHAN MAHAJAN said:
1 decade ago
We can't used void with variables declaration. Because it is derived data type and is used for Function.
Ritesh bhadani said:
1 decade ago
Here void represents that v may take any data type, so c compiler will be dangled regarding variable v.
DATTA BACHATE said:
1 decade ago
First convert this void type pointer to basic data types then we can implement it as normal variable.
Lohija said:
2 decades ago
One should not declare as the datatype because the void data type can be used for pointer variables.
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
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers