'What is a valid return type for a pointer function in C?
The function *getString() is intended to return the address of the local variable a. However, it gives a warning: return from incompatible pointer type [-Wincompatible-pointer-types]. What would be a valid return type for this function?
#include <stdio.h>
char *getString()
{
char a[] = "Hello World";
return &a;
}
int main()
{
printf("%s", getString());
getchar();
return 0;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
