What will be the output of the following C code?
Question 1:
// Date:2020/4/3
// Author:xiezhg5
#include <stdio.h>
#include <string.h>
int main(void)
{
char*str="hello, world\n";
char strc[]="good moring\n";
strcpy(strc,str);
printf("%s\n",strc);
return 0;
}
// hello, world
Question 2:
// Date:2020/4/3
// Author:xiezhg5
#include <stdio.h>
#include <string.h>
int main(void)
{
char str[]="hello, world\n";
str[5]='.';
printf("%s\n",str);
return 0;
}
// hello. world
Question 3:
// Date:2020/4/3
// Author:xiezhg5
#include <stdio.h>
#include <string.h>
int main(void)
{
char *str="hello world";
char strary[]="hello world";
printf("%d %d\n",sizeof(str),sizeof(strary));
return 0;
}
// 4(32位系统) 12
Question 4:
// Date:2020/4/3
// Author:xiezhg5
#include <stdio.h>
#include <string.h>
int main(void)
{
char *str="hello world";
char strary[]="hello world";
printf("%d %d\n",strlen(str),strlen(strary));
return 0;
}
// 11 11
Question 5:
// Date:2020/4/3
// Author:xiezhg5
#include <stdio.h>
#include <string.h>
void f(char *k)
{
k++;
k[2]='m';
printf("%c\n",*k);
}
int main(void)
{
char s[]="hello";
f(s);
return 0;
}
// e
Question 6:
// Date:2020/4/3
// Author:xiezhg5
#include <stdio.h>
#include <string.h>
void f(char *k)
{
printf("%s\n",k);
}
int main(void)
{
char s[]="hello";
f(s);
return 0;
}
// hello