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 1 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?
Mymuna said:
2 decades ago
Correct.
Sandeep said:
2 decades ago
I run it on Dev C IDE then the error variable or field v declared void!
Mohsin said:
2 decades ago
v and *vptr is declared as void pointers and we cannot use v and *vptr until and unless we convert that variables to the desired data type.
Here we are assigning value 0 to v and v doent hold any memory location to assign the value first we have to convert void v to integer type then only we can assing the value to it.
Ex (int) v = 0 ;
or v = (int) 0 ;
Anything I am not sure.
Here we are assigning value 0 to v and v doent hold any memory location to assign the value first we have to convert void v to integer type then only we can assing the value to it.
Ex (int) v = 0 ;
or v = (int) 0 ;
Anything I am not sure.
Ambi said:
1 decade ago
You can never create a void variable. Only Creation of void pointer is possible.
Deepu said:
1 decade ago
void is a primary data type. We are using variable name of void type and intialized as zero then what is wrong in that?
Jyothi said:
1 decade ago
Void means which not return any thing. If you put void in front of main function means that is not return any thing.
So, void should not be used for declaring the variable data types otherwise it shows error.
So, void should not be used for declaring the variable data types otherwise it shows error.
Shashi bhushan vishwakarma said:
1 decade 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);
Nithin said:
1 decade ago
void is a return type and variable should not declare to it.
Gertin samules said:
1 decade ago
void datatype wont allocate any memory so if void type means nothing but void* makes sense when sending generic type of data to functions and they act like generic pointers which can be converted to other types..
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers