欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Character Pointers and Functions.c

程序员文章站 2022-03-11 18:41:17
...

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
相关标签: sanfoundry