i didn't found any problem with option a also
@Shaik Masthan
Shouldn't A and B should also be correct ?
@Shiv Gaur
OPTION B should be wrong
@balaganesh
what is the answer they provided?
i hope they mistakenly type option a
(a) charPtr= voidPtr
instead of
(a) *charPtr= *voidPtr
if this is the original option, then only Option D is correct,
otherwise option A and Option D , both are correct
srestha de-referencing void pointer is not allowed so *voidPtr will give error
you can't directly de-reference the void pointer
correct syntax of option C ===> *(char *)voidPtr=*charPtr
@Shaik
*charPtr= *voidPtr
then how do we dereference a char pointer and assign a void pointer value?
Some interesting facts point 1
https://www.geeksforgeeks.org/void-pointer-c/
this is incorrect
int main() { int a = 10; void *ptr = &a; printf("%d", *ptr); return 0; }
int main()
int
main()
{
int a = 10;
a = 10;
void *ptr = &a;
void
*ptr = &a;
printf("%d", *ptr);
printf
(
"%d"
, *ptr);
return 0;
return
0;
}
See this, it gives compiler error
then how d will be correct
See this..
can u tell me one last thing, where this copying is actually.
i didn't get it
I mean one memory adress is copying in another pointer variable
where practically we need to do this?
is it like call by reference?
Yes kind of.. but like in call by ref, the pointer can manipulate the value by de-referencing but in this case we cannot change value of c by *voidPtr.
we can use, void pointer for implementing function overloading in C
64.3k questions
77.9k answers
244k comments
80.0k users