1char * createStr() {
2
3 char char1= 'm';
4 char char2= 'y';
5
6 char *str = malloc(3);
7 str[0] = char1;
8 str[1] = char2;
9 str[2] = '\0';
10
11 return str;
12
13}
14
1#include <stdio.h>
2
3int main()
4{
5 char *p="abcd";
6 printf("%c\n", p[0]);
7 printf("%c\n", p[1]);
8 printf("%c\n", p[2]);
9 printf("%c\n", p[3]);
10 return 0;
11}
12
1#include <stdio.h>
2#include <string.h>
3 char* createStr(){
4 static char str[20] = "my";
5 return str;
6}
7int main(){
8 char a[20];
9 strcpy(a,createStr()); //this will copy the returned value of createStr() into a[]
10 printf("%s",a);
11 return 0;
12}
13