What is meaning of suspicious pointer conversion in c?

Answer:
When you will assign a particular type pointer variable with address of different type, such type of automatic type conversion is known as suspicious type conversion. In turbo c compiler it is not cause of any compilation error but compiler will send one warning message: suspicious pointer conversion. So we should avoid suspicious pointer conversion.



 Examples of suspicious pointer conversion:
#include<stdio.h>
void main(){
    int i=10;
int *p,**q;
float *r;    

q=p;      //suspicious pointer conversion
q=&i;   //suspicious pointer conversion
p=r;    //suspicious pointer conversion
p=(int **)10;   //suspicious pointer conversion
printf("%d %d %d",*p,**q,*r);
}
Avoid writing above code that way. You may get undesired results. Write above code in the following manner:
#include<stdio.h>
void main(){
    int i=10;
int *p,**q;
float *r;    

q=&p;    // or q=(int **)p; 
//Note. Both are different statement, change according to requirement. 
q=(int **)&i;  
p=(int *)r;   
p=(int *)10;  
printf("%d %d %d",*p,**q,*r);
}

No comments: