C Programming - Pointers - Discussion
Discussion Forum : Pointers - True / False Questions (Q.No. 3)
3.
The following program reports an error on compilation.
#include<stdio.h>
int main()
{
float i=10, *j;
void *k;
k=&i;
j=k;
printf("%f\n", *j);
return 0;
}
Answer: Option
Explanation:
This program will NOT report any error. (Tested in Turbo C under DOS and GCC under Linux)
The output: 10.000000
The output: 10.000000
Discussion:
23 comments Page 2 of 3.
Tripti said:
1 decade ago
It produce an error b/c j does not define as a double pointer and we send in it an address of address.
Rahul said:
1 decade ago
The above code is correct. It gave no error during compilation or during running in gcc.
Suki said:
1 decade ago
Can you explain what is typecast?
Harshu smart boy said:
1 decade ago
What is possible error?
Abi said:
1 decade ago
Hi,
Can you explain then why do we need to typecast a void pointer?
Can you explain then why do we need to typecast a void pointer?
Shabana said:
1 decade ago
Yes its correct because void is nothing we cannot assign like that.
Kiran ware said:
1 decade ago
Yes, before assigning the void pointer we must typecast it.
Ankit said:
1 decade ago
But before assigning the void pointer we must typecast it. Right ?
Kunal Bansal said:
1 decade ago
@kranthi this is an valid prototype
error is because of different thing , read my previous comment
error is because of different thing , read my previous comment
Kunal Bansal said:
1 decade ago
I have personally run this program on DEV C++ 4.9.9.2 and it was giving error in line j=k; statement
After type casting it , it is giving the value 10.000000
So this is compiler dependent
After type casting it , it is giving the value 10.000000
So this is compiler dependent
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers