当前位置:三九宝宝网 → 宝宝教育 → 教学论文 → 正文

c语言面试题关于字符串还有字符指针

更新:02-03 整理:39baobao.com
字体:

[c语言写一个函数能将两个字符串连接在主函数中调用]这样就可以了,我已经在vc6通过调试运行了,不过要注意一点哦,虽然c语言里面没有string类型的变量,但是在c++里面有,所以为了防止不必要的麻烦,你这里的变量名字最好不要用string #i...+阅读

str是个字符指针,也可以表示为字符数组或者字符串,str = &a;表示str指向的地方只能存下一个字符。

strcpy(str, “hello”);

肯定放不下hello啊,所以会有内存错误

如果你不相信,你把hello换成空串""试试,因为空串占用1字节,str指向的地方能放下。

如果你想知道更多,那么试试下面的这段程序:

#include

#include

void main(void) {

int a;

char *str = (char *) &a;

strcpy(str, "abc");

printf(str);

}这段之所可以是因为int类型占4个字节,"abc"也占4个,能放下,"abcd"就不行。

懂了吗?

本文地址:https://www.39baobao.com/show/29_35323.html

以上内容来自互联网,请自行判断内容的正确性。若本站收录的信息无意侵犯了贵司版权,请联系我们,我们会及时处理和回复,谢谢.

以下为关联文档:

c语言编程从键盘上输入一个字符串通过函数调用的方法使该字符串1 输入字符串; 2 调用函数进行翻转,可以通过将对称位置字符交换值实现; 3 输出结果。 代码如下: void revers(char *s) { char *p=s,c; while(*p)p++; p--; while(p>s) { c = *p...

C语言中如何编写一个字符串复制函数并在主函数中调用它#include<stdio.h> char *custom_cpy(char *to,char *from); int main(int argc,char *argv[]){ char *from = "i like c langanger"; char to[30]; char *ptr = custom_cpy(t...

编C语言程序:用自定义函数实现字符串处理函数strcat strcpy/*** *char *strcat(dst, src) - concatenate (append) one string to another * *Purpose: * Concatenates src onto the end of dest. Assumes enough * space in dest. *...

c语言问题调用函数输入5个字符串我的代码有什么问题void shuru(char *p) { int j; char o[5][20]; for(j=0;j<5;j++) gets(o[j]); p=o; } 改为: #include void shuru(char **p) { int j; char o[5][20]; for(j=0;j<5;j++) gets...

如何用c语言实现:在主函数中输入一个字符串调用函数将其中的所#include void p(char[]); int main(void) { char a[100]; gets(a); p(a); printf("%s\n",a); return 0; } void p(char a[]) { int i,j; for(i=0;a[i+2];i++) if(a[i]=='a'&a...

C语言关于字符串的操作函数有哪些string.h头文件中包含的字符串函数 void *memcpy(void *dest, const void *src, size_t n);//将n字节长的内容从一个内存地址复制到另一个地址;如果两个地址存在重叠,则最终行...

c语言结构体字符型指针赋值#include <stdio.h> #include <malloc.h> #include <string.h> struct Test { int id; char* name; }; int main(int argc, char **argv) { struct Test* test; test = mall...

c语言中怎样将结构体转换成字符串基本要求 1.具有计算机的基础知识。 2.了解操作系统的基本概念,掌握常用操作系统的使用。 3.掌握基本数据结构和常用算法,熟悉算法描述工具――流程图的使用。 4.能熟练地使用...

c语言常见面试题网上找的 #include int cal(int h1,int length,int b[]); int main(){ unsigned int n[]=; int length=7; printf("%d",cal(-2,length,n)); return 0; } int cal(int h1,int l...