/*here I am trying to return an integer pointer even when the return
type of the function is int and it works ,just gives warning*/
void main()
{
int fun1(),*ip;
clrscr();
ip=fun1();//warning-non-portable pointer conversion
printf("\nip=%u",ip);
getch();
}
int fun1()
{
int a;
return &a;//warning-non-portable pointer conversion
}
/*here I am trying to return a character pointer even when the
return type of the function is char and it does not work,it gives
error*/
void main()
{
char fun1(),*cp;
clrscr();
cp=fun1();//warning-non-portable pointer conversion
printf("\ncp=%u",cp);
getch();
}
char fun1()
{
char a;
return &a;//error-non-portable pointer conversion
}
/*here I am trying to return a float pointer even when the return
type of the function is float and it does not work,it gives errors*/
void main()
{
float fun1(),*fp;
clrscr();
fp=fun1();//error-illegal use of floating-point
printf("\nfp=%u",fp);
getch();
}
float fun1()
{
float a;
return &a;//error-incompatible type conversion
}
/*here I am trying to return a struct student pointer even when the
return type of the function is struct student and it does not
work,it gives errors*/
struct student
{
int age;
char *name;
};
void main()
{
struct student fun1(),*sp;
clrscr();
sp=fun1();//error-illegal structure opretion
printf("\nsp=%u",sp);
getch();
}
struct student fun1()
{
struct student a;
return &a;//error-incompatible type conversion
}
I want to ask that if we return a pointer to int when the function's
return type is int.It works.It does not give any error.But in case
of others' data type ,it gives error.
Why and how does it happen?