锐捷网络-嵌入式软件部分笔试题-2012/09/13

只是部分题目,凭记忆,仅供参考!

1、

#include <stdio.h>

int main(void)
{
	int a[100][200];

	printf("%d\n",&a[37][45]-&a[0][3]);//37*200+(45-3)=7442,这里两个求的就是两个元素的距离

	return 0;
}

2、将变量a的第n为设置成0,其他位不变

//32位,最右边的是第一位下标为0,n<31
#include <stdio.h>

#define SETBIT_0(a,n) (a & ~(0x0001 << (n)))//将第n位置0
#define SETBIT_1(a,n) (a | (0x0001 << n))//将第n位设置1

int main(void)
{
	int a = 10;
	int b = 10;
	a = SETBIT_0(a,3);
	b = SETBIT_1(b,0);
	printf("%d,%d\n",a,b);
	return 0;
}

3、打印n=-1,输出-1,n= +1时,输出+1;

#include <stdio.h>

int main(void)
{
	int a = -1;
	int b =  1;

	printf("%d,%+d\n",a,a);
	return 0;
}

4、 printf("%d\n",(int)(&(*(ptr+1))[2]));//答案128

#include <stdio.h>

int main(void)
{
	int (*ptr)[5] = (int(*)[5])100;

	printf("%d\n",(int)(&(*(ptr+1))[2]));//答案128

	return 0;
}

ptr = 100;

ptr+1 = 100+4*5 = 120;

(*(ptr+1))[2] =  “ptr下一个单元的指向下标为2的元素内容的某个值”

&(*(ptr+1))[2],去这个值的地址

5、一个小写字母转换成大写之母的库函数

extern int toupper(int c);

#include <stdio.h>

#include <ctype.h>
int main(void)
{
	char *s="Hello, World!";
	int i;

	printf("%s\n",s);
	for(i=0;i<strlen(s);i++)
	{
		putchar(toupper(s[i]));
	}
	getchar();
	return 0;
}

// 转换成大写 , 函数参数为字符数组
// 利用字符串数组的结尾都是 \0
void ToUpper(chars[])
{
       int i=0;
       while(s[i++]!='\0' )
       {
              // 判断是否是小写字母
              if(s[i]>='a' && s[i]<='z' )
                     s[i] -= 32;     // 小写字母比大写字母的 ASCII 大 32
       }
}
 
// 转换成大写 , 函数参数为字符指针
void ToUpperPtr(char* s)
{
       while(*s != '\0')
       {
// 判断是否是小写字母
              if(*s >='a' && *s <='z')
                     *s -= 32;      // 小写字母比大写字母的 ASCII 大 32
              s++; // 指针的地址 ++
       }
}

6、有个三维数组的题忘了,希望有人补充

int main(void)
{
	int p[3][4][5];
	int *q = (int *)p;
	int (*s)[5] = &p[1][0];
	int i,m;

	for(i = 0; i < 60; i++)
		q[i] = i;
	printf("%d\n",p[1][7][1]*(*(s+1)[3]));
	return 0;
}



7、程序填空

内核中list.h中内核的插入节点的函数

static inline void __list_add(struct list_head *new,
     struct list_head *prev,
     struct list_head *next)
{
next->prev = new;//head->next->prev,图中的1即第1步
new->next = next;//图中的1即第2步
new->prev = prev;//图中的1即第3步
prev->next = new;//head->next,//图中的1即第4步,包括打黑X的部分
}

最后两行是答案。

http://blog.csdn.net/hubi0952/article/details/7720462这里讲的很清楚

8、程序填空

strcmp函数的填空,答案是return (c1-c2)

9、strstrip()

 C标准库没有提供,但经常用到一个字符串相关函数
  原型:char *strstrip(char *s)
  参数:s是一个字符串
  返回值:返回一个字符串
  功能:去掉字符串s中的前后空白符(制表符、空格、回车等),并将该字符串返回。
  一种实现:
  char *strstrip(char *s)
  {
  size_t size;
  char *end;
  size = strlen(s);
  if (!size)
  return s;
  end = s + size - 1;
  while (end >= s && isspace(*end))
  end--;
  *(end + 1) = '\0';
  while (*s && isspace(*s))
  s++;
  return s;
  }

原型:extern int isspace(int c);
  
  用法:#include <ctype.h>
  
  功能:判断字符c是否为空白符
  
  说明:当c为空白符时,返回非零值,否则返回零。
     空白符指空格、水平制表、垂直制表、换页、回车和换行符。
  
  举例:

      // isspace.c
      
      #include <syslib.h>
      #include <ctype.h>

      main()
      {
        char s[]="Test Line 1\tend\nTest Line 2\r";
        int i;
        
        clrscr();        // clear screen
        for(i=0;i<strlen(s);i++)
        {
          if(isspace(s[i])) putchar('.');
          else putchar(s[i]);
        }
        getchar();
        return 0;
      }

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值