1 votes 1 votes consider the two declarations void *voidPtr; char *charPtr; which of the following assignments are syntactically correct? (a)charPtr= voidPtr (b)*charPtr=voidPtr (c)*voidPtr=*charPtr (d)voidPtr=charPtr please explain! Programming in C pointers + – balaganesh asked Aug 31, 2018 balaganesh 4.1k views answer comment Share Follow See all 25 Comments See all 25 25 Comments reply Shaik Masthan commented Aug 31, 2018 reply Follow Share as per my knowledge, option D is correct. what is the given answer? 0 votes 0 votes balaganesh commented Aug 31, 2018 reply Follow Share why option a is not correct? 0 votes 0 votes Shaik Masthan commented Aug 31, 2018 reply Follow Share i didn't found any problem with option a also 0 votes 0 votes Shiv Gaur commented Aug 31, 2018 reply Follow Share @Shaik Masthan Shouldn't A and B should also be correct ? 0 votes 0 votes Shaik Masthan commented Aug 31, 2018 reply Follow Share @Shiv Gaur OPTION B should be wrong 0 votes 0 votes balaganesh commented Aug 31, 2018 reply Follow Share Option B and C are not correct : because charPtr is indicates a pointer points to a char. voidPtr is a pointer points to void , since *charPtr is character it will not store an adress of void, similarlly option C is incorrect 1 votes 1 votes Shaik Masthan commented Aug 31, 2018 reply Follow Share @balaganesh what is the answer they provided? 0 votes 0 votes balaganesh commented Aug 31, 2018 reply Follow Share option D is the answer. 0 votes 0 votes Shaik Masthan commented Aug 31, 2018 reply Follow Share @balaganesh 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 0 votes 0 votes srestha commented Aug 31, 2018 reply Follow Share then what about c)? 0 votes 0 votes MiNiPanda commented Aug 31, 2018 reply Follow Share srestha de-referencing void pointer is not allowed so *voidPtr will give error 0 votes 0 votes Shaik Masthan commented Aug 31, 2018 reply Follow Share you can't directly de-reference the void pointer correct syntax of option C ===> *(char *)voidPtr=*charPtr 1 votes 1 votes srestha commented Aug 31, 2018 reply Follow Share @MiniPanda any standard resource about it? 0 votes 0 votes srestha commented Aug 31, 2018 reply Follow Share @Shaik *charPtr= *voidPtr then how do we dereference a char pointer and assign a void pointer value? 0 votes 0 votes MiNiPanda commented Aug 31, 2018 reply Follow Share Some interesting facts point 1 https://www.geeksforgeeks.org/void-pointer-c/ 1 votes 1 votes Shaik Masthan commented Aug 31, 2018 reply Follow Share *charPtr= *voidPtr this is incorrect 0 votes 0 votes srestha commented Aug 31, 2018 reply Follow Share int main() { int a = 10; void *ptr = &a; printf("%d", *ptr); return 0; } See this, it gives compiler error then how d will be correct 0 votes 0 votes MiNiPanda commented Aug 31, 2018 reply Follow Share We are not de-ferencing void pointer in D.. we are just copying the address of a char variable into void pointer..that is allowed 1 votes 1 votes srestha commented Aug 31, 2018 reply Follow Share ok , thank u :) can u tell me one last thing, where this copying is actually. I think, I havenot seen this before 0 votes 0 votes MiNiPanda commented Aug 31, 2018 reply Follow Share See this.. 1 votes 1 votes Shaik Masthan commented Aug 31, 2018 reply Follow Share can u tell me one last thing, where this copying is actually. i didn't get it 0 votes 0 votes srestha commented Aug 31, 2018 reply Follow Share @Minipanda is it like call by reference? 0 votes 0 votes srestha commented Aug 31, 2018 reply Follow Share @Shaik I mean one memory adress is copying in another pointer variable where practically we need to do this? 0 votes 0 votes MiNiPanda commented Aug 31, 2018 reply Follow Share 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. 1 votes 1 votes Shaik Masthan commented Aug 31, 2018 reply Follow Share where practically we need to do this? we can use, void pointer for implementing function overloading in C 1 votes 1 votes Please log in or register to add a comment.
0 votes 0 votes voidptr = charptr Pankaj_Saini answered Aug 14, 2019 Pankaj_Saini comment Share Follow See all 0 reply Please log in or register to add a comment.