Functions returning Strings in C

Functions can also return string values in C/C++. String is a constant variable so we have used const keyword for functions declaration and definition.

Example

#include<stdio.h>
#include <stdio.h>
const char * getString(); // strings are constant always
int main()
{
	printf("hello this ");
	printf("%s\n", getString());
	getchar();
	return 0;
}

const char * getString()
{
	char *x = "world";
	return x;
}

Output

hello this world