C Programming - Pointers - Discussion
Discussion Forum : Pointers - Yes / No Questions (Q.No. 5)
5.
Will the following program give any warning on compilation in TurboC (under DOS)?
#include<stdio.h>
int main()
{
int *p1, i=25;
void *p2;
p1=&i;
p2=&i;
p1=p2;
p2=p1;
return 0;
}
Discussion:
21 comments Page 2 of 3.
Sangee said:
1 decade ago
Error :invalid conversion from void* to int *.
Diksh said:
1 decade ago
I agreed with sonal.
(1)
Tanvi said:
1 decade ago
It is compiling on Turbo C. Ideally it should not as yes, arithmetic cannot be performed on Void Pointer.
(1)
Anshu said:
1 decade ago
This program will not give any error or warning on gcc compiler until and unless we will not try to print p2 value.
But if we try to print p2 value it will give an error such as:
Warning: dereferencing 'void *' pointer
Error: invalid use of void expression.
So solve this this kind of error,we need to typecast the void pointer.
Such as:
printf("value of p2 is %d
",*(int*)p2);
Thank you.
But if we try to print p2 value it will give an error such as:
Warning: dereferencing 'void *' pointer
Error: invalid use of void expression.
So solve this this kind of error,we need to typecast the void pointer.
Such as:
printf("value of p2 is %d
",*(int*)p2);
Thank you.
(4)
Kariyappa said:
1 decade ago
No error, because void pointer can take any datatype.
(1)
DjRahul said:
1 decade ago
But we didn't typecast it and still we are using it how?
Divya said:
9 years ago
It's impossible.
(1)
Aarzu said:
9 years ago
What is use of void pointer?
Raj said:
9 years ago
Please explain it.
Srisailam said:
8 years ago
In GCC compiler showing no error and no output.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers