non portable pointer conversion Warning

c, pointers

Solution

The warning is solved..why it is occuring? please explain..?

You were missing the prototype for `malloc`, so the compiler assumed a return type of `int`.

char *p=malloc(100);

Assigning an `int` to a `char*` gives the warning. Apparantly they are the same size in your compiler, but they aren't the same size everywhere.

When you added the prototype (in your case by including `stdlib`), the compiler is told that the return type of `malloc` is `void*`. `void*` is a pointer type that can be assigned to any other pointer type without a cast.

Problem

``` #include<stdio.h> #include<conio.h> int main() { char *p=malloc(100); clrscr(); printf("enter your name\n"); scanf("%s",p); printf("%s",p); getch(); return 0; } ``` when compiling this c program "non portable pointer conversion" warning is occuring..What is the reason for the warning?

Original source