1 1 vote What is the output for this code ? Programming in C programming-in-c + – set2018 1.6k views answer comment Share Follow Print See all 13 Comments 13 13 Comments reply saxena0612 commented Aug 9, 2017 reply Follow flag Is it 2? 0 0 replyShare set2018 commented Aug 9, 2017 reply Follow flag yes ,explain pls 0 0 replyShare saxena0612 commented Aug 10, 2017 reply Follow flag Here ptr is a general pointer and pointing to the array of two integers .Here general means that pointer doesn`t know that to which data type it is pointing to. In statement of incrementing we incremented it with a size of integer and thus it will jump 4 bits(depends on OS) and point to next memory location but in array that memory is hold by 2. And finally in print statement since you can`t derefernce void pointer thats why its cast to int and dereferenced. 1 1 replyShare joshi_nitish commented Aug 10, 2017 reply Follow flag i think it is compiler dependent, in this qsn asnwer could be 2 only if we assume void pointer size=1, then after performing ptr=ptr+sizeof(int), it will hop 4 bytes ahead and point to A[1]. 0 0 replyShare saxena0612 commented Aug 10, 2017 reply Follow flag @joshi_nitish : Since its an array of integers and we are incrementing the ptr pointer by the size of integer! Then it will point to the next element of the array anyway? Is there any clause related to size of void pointers ? 0 0 replyShare set2018 commented Aug 10, 2017 reply Follow flag @ saxena0612 "pointer doesn`t know that to which data type it is pointing to." but after assinging address of int a it will point to adresss of some interger value na ? m confused in line no 3 wht does it mean ? 0 0 replyShare set2018 commented Aug 10, 2017 reply Follow flag @ joshi_nitish how 4 bytes explain this pls ? u r right tht it is compiler dependent, in this qsn asnwer could be 2 only if we assume void pointer size=1 but again how pointer size is define for this program ? 0 0 replyShare saxena0612 commented Aug 10, 2017 reply Follow flag Understand this way! You only stored the first element address in ptr i.e think of ptr as a variable and you stored the address of first element of array ! but the type is not yet defined i.e you can`t say like ptr is pointing to a 4 byte of memory whose starting address is &a. 0 0 replyShare set2018 commented Aug 10, 2017 reply Follow flag ohk ptr point to starting address lets assume 0 after that sizeof(int) will add to the ptr ptr=ptr+sizeof(int) now how u know tht it will now point to second element of array ? 0 0 replyShare saxena0612 commented Aug 10, 2017 reply Follow flag Check this code snippet. 0 0 replyShare set2018 commented Aug 10, 2017 reply Follow flag @ saxena0612 see this ,using sizeof(int ) it also take 4 bytes thts why m asking size of void pointer is considering to be a int size . now here is the point tht wht is the size of void pointer .even pointer size is irrespective of data type but in case of void ?thts my doubt 0 0 replyShare set2018 commented Aug 10, 2017 reply Follow flag also see this https://gateoverflow.in/142867/pointer 0 0 replyShare saxena0612 commented Aug 10, 2017 i edited by saxena0612 Aug 10, 2017 reply Follow flag You code is exactly same like mine ! except for the fact that i coded 4 directly and you are using the sizeof(int) which is 4 anyway because if you would find size of int it is 4 bytes !(may vary on os) All the options on other question are wrong . The correct statement is: It will compile and run successfully but size of void pointer is definely depends on platform . Here i am using 64 bit and gnu compiler and still size of void pointer is 4 bytes . whereas people mentioned that its 8 bytes in 64 bit processor . For better understanding : https://stackoverflow.com/questions/692564/concept-of-void-pointer-in-c-programming 0 0 replyShare Please log in or register to add a comment.