Take a sting constant "efgh" declare as character pointer type.take the value of "efgh" pass to anther "a" string constant.The "a" string constant is declared as character pointer type too.
But it did not shows the output of "efgh" on console.Because the "a" pointer has not point to the "c" array first address after executed the "for" statement.
The code as follows"
#include"stdio.h"
#include"stdlib.h"
main(){
char *a="abcd";
char *b="efgh";
char c[10];
int i=0;
for(;*b!='\0';b++,a++,i++){
c[i]=*b;
a=&c[i];
}
printf("%s\n",a);
system("pause");
}
So how to modify?
The modified as follows:
#include"stdio.h"
#include"stdlib.h"
main(){
char *a="abcd";
char *b="efgh";
char c[10];
int i=0;
for(;*b!='\0';b++,a++,i++){
c[i]=*b;
}
c[i]='\0';
a=c;
printf("%s\n",a);
system("pause");
}
Good post
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thank you for continuing to share your journey on the Programming Community. Upvoted!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit