1、
#include <stdio.h> void put_string(const char *s) // 传入的实参为指针,在数组中,指向首个字符的指针的行为和数组本身一样。 { printf("%s ", s); // 显示数组本身。 } int main(void) { char str[128] = "abcd"; put_string(str); //实参为字符串名,也就是数组名, 数组名解释为指向数组的第一个元素的指针, 该指针的行为和数组本身一样。 return 0; }
2、
#include <stdio.h> void put_s(const char *s) { printf("%s ", s); } int main(void) { char *str = "abcde"; put_s(str); return 0; }
3、
#include <stdio.h> void put_st(const char *s) { putchar(*s); while(*s++) { putchar(*s); } } int main(void) { char str[128]; printf("str = "); scanf("%s", str); put_st(str); return 0; }
4、
#include <stdio.h> #include <string.h> void put(const char *x) { int i; int len; len = strlen(x); for(i = 0; i < len; i++) { printf("%c", *x++); } } int main(void) { char str[128] = "abcde"; put(str); return 0; }
5、
#include <stdio.h> #include <string.h> void put_s(const char *x) { int i; int len = strlen(x); for(i = 0; i < len; i++) putchar(*x++); } int main(void) { char str[128] = "abcdef"; put_s(str); return 0; }
6、
#include <stdio.h> void put(const char *x) { while(*x) printf("%c", *x++); } int main(void) { char str[128] = "abcdef"; put(str); return 0; }