珠海全志科技软件笔试题
1、char a[] = "ab\n\\012\""; strlen(a) = 8 .
注释:8个字符分别为 'a' 'b' '\n' '\\'(反斜线符"\",“\\0”是两个字符) '0' '1' '2' ' /" '(双引号符)
2、int (*ptr)();是什么作用?
答:表示申明了一个函数指针变量ptr,举例:
【例 10.31】本例用来说明用指针形式实现对函数调用的方法。 int max(int a,int b)
{ if(a>b)return a; else return b; }
main()
{ int max(int a,int b); int(*pmax)();
int x,y,z; pmax=max; printf("input two numbers:\n"); scanf("%d%d",&x,&y); z=(*pmax)(x,y); printf("maxmum=%d",z); }
3、#define fun(x) x+x,5*fun(5)=30 宏定义只是单纯的替换
4、在ARM9(32位机器)平台上,
struct S
{
char c;
int i;
};
sizeof(S) = 8(最大长度的整数倍)
5、请写一段程序,删除一个单向链表的一个结点。
typedef int ElemType;typedef int Status;#define ERROR 0#define OK 1 typedef struct Node{ElemType data;struct Node *next;}Node, *LinkList;Status DeleteNode(LinkList L, int pos){LinkList ptr = L;LinkList p = L;int index = 1;if (pos < 0){return ERROR;}while (ptr->next!=NULL && index<pos){++index;ptr = ptr->next;}if (ptr == NULL){return ERROR;}p = ptr;ptr = ptr->next;free(p);return OK;}
int strreplace(char *origine, char *target, char *rpl){int origStrLen = strlen(origine);int pos = -1;int prePos = pos;int i = 0;int j = 0;int index;if (strlen(target) != strlen(rpl)){printf("there is a false\n");return ERROR;}while (i != origStrLen){j = 0;//每次从头开始从新查找子串while (origine[i]!=NULL && target[j]!=NULL){if (origine[i] == target[j]){++i;++j;}else{i = i - j + 1;j = 0;}}if (target[j] == NULL){prePos = pos;pos = i - j;}if (pos!=-1 && pos!=prePos){for (index = pos; index < pos+strlen(target); index++){origine[index] = rpl[index - pos];}}printf("%d\n", i);}return OK;}