1 votes 1 votes (5) Would the following program give a compilation error or warning? main() { float i = 10, *j; void *k; k=&i; j= k; printf("\n%f", *j); } Programming in C programming-in-c + – ermp888 asked Jun 30, 2018 • edited Jul 1, 2018 by srestha ermp888 846 views answer comment Share Follow See all 8 Comments See all 8 8 Comments reply Show 5 previous comments SuvasishDutta commented Apr 18, 2019 reply Follow Share This program will compile and run in C compiler but it will give compiler error with C++ compiler in line no 6( j=k ) 0 votes 0 votes srestha commented Apr 18, 2019 reply Follow Share @SuvasishDutta isit because of return type? 0 votes 0 votes SuvasishDutta commented Apr 18, 2019 reply Follow Share Yes because of void pointer. Void pointer is a pointer that has no associated data type with it. 1. Assigning content of pointer of any type to a void pointer will work fine in all compilers. 2. Assigning content of a void pointer to a pointer of any type will produce error in some compilers e.g. in c++. It is compiler dependent. In the question, there is an invalid conversion from 'void *' to 'float *'. It doesn't happen implicitly. We have to typecast the void pointer with the data type to which content of void pointer is assigned. Here, to make the code to run fine in all compilers, we have to write : j= (float *)k in place of j=k. 2 votes 2 votes Please log in or register to add a comment.
0 votes 0 votes It will give compilation error as void is not any data type. Pragya123 answered Apr 18, 2019 Pragya123 comment Share Follow See all 0 reply Please log in or register to add a comment.