嵌入式笔试刷题专栏(第二天)

11.请你定义如下几种函数,函数没有形参,但是有返回值类型,返回值类型(只要类型符合要求就行)要求如下

返回函数指针

int (*func1(void))(void);

返回指针数组

int *(*func2(void))[3];

返回数组指针

int (*func3(void))[5];

返回函数数组指针

int (*(*func4(void))[2])(int);

11. 定义函数:

  • 返回函数指针的函数:
  • 返回指针数组的函数:
  • 返回数组指针的函数:
  • 返回函数数组指针的函数:

12.const char *a;

  const *char a;

  char *const a;   有什么不同

12. const 用法区别:

  • const char *a;:指向常量字符,不能通过 a 修改内容。
  • const *char a;语法错误
  • char *const a;:常量指针,指针本身不能修改,内容可以改。

13.#define CALC(x,y)  x*y+x

   int main()

   {

       int  a=CALC(2*3,3+2);

       printf(result=%d\n,a);

       return 0;

}

13. 宏展开结果:

#define CALC(x,y)  x*y+x
int a = CALC(2*3, 3+2); // 实际变为 2*3*3+2 = 18 + 2 = 20

输出:result=20

14分析如下写法的含义

第一题: void *(*(p)(int))[10];

                         函数名:p是函数名字

                         函数的形参: int

                         函数的返回值:void *[10]   返回的是一个指针数组

          第二题: float (*(*p)(int,int,float))(int);

                         p是函数指针的名字

                         p指向的函数指针,参数是int,int,float

                         p指向的函数指针,  返回值类型是float  (int),返回值也是个函数指针

          第三题:typedef double (*(*(*p)())[10])();

                         p是函数指针的名字

                         p指向的函数指针,参数是空的

                         p指向的函数指针,返回值是double *[10]()   返回值是函数指针数组

          第四题:int (*(*p())[10])();

                         函数名:p

                         函数的形参:空的

                         函数的返回值:int *[10]()    返回值是函数指针数组

14. 复杂声明分析:

  • 第一题:p 是函数,参数为 int,返回 void * 指针数组。
  • 第二题:p 是函数指针,返回值是函数指针,参数为 int,返回 float。
  • 第三题:p 是函数指针,返回指向包含10个 double() 函数指针的数组。
  • 第四题:p 是函数,返回一个指向10个 int() 函数指针数组的指针。

15.写出以下程序执行结果

# include <stdio.h>

void  main( )

{  

char  s1[]="Hello World!";

char  s2[]="Hello World!";

if(s1==s2 )//比较两个指针中存放的地址是否相同

printf(“Equal!”);

else

printf(“Not equal!”);

}

15. 输出结果:

char s1[] = "Hello World!";
char s2[] = "Hello World!";
if (s1 == s2)
    printf("Equal!");
else
    printf("Not equal!");

输出:Not equal!

16.# include <stdio.h>

void  main( )

{  

char  s[]="Hello World!";

char* p = s;

int n=10;

printf("%d %d %d %d\n",sizeof(s),sizeof(p),strlen(p),sizeof(n));

}

16. 输出结果:

char s[] = "Hello World!";
char* p = s;
int n = 10;

输出:13 4 12 4(32位系统)

17.#include <stdio.h>

void swap (int *p1,int *p2)

{

int t ;

    int* p;

    t= *p1;

*p1= *p2;

    *p2=t;

    p = p1;

    p1=p2;

    p2 = p;

}

void swap2(int ** m, int** n)

{ int* p;

p=*m;

*m =*n;

*n = p;

}

void main( )

{  

  int a=1,b=2,*p=&a,*q=&b;

  swap(p,q);

  printf("%d,%d,%d,%d,",a,b,*p,*q);

  swap2(&p,&q);

  printf("%d,%d,%d,%d\n",a,b,*p,*q);

}

17. 输出结果:

swap(p, q);
printf("%d,%d,%d,%d,", a, b, *p, *q);
swap2(&p, &q);
printf("%d,%d,%d,%d\n", a, b, *p, *q);

输出:2,1,2,1,2,1,1,2

18.# include <stdio.h>

void merge (char  *d, int size,char* s1,char* s2)

{    

while ( *s1 != 0  &&  *s2 != 0)

{

if  (*s1 < *s2)

*d++ = *s1++;

else

*d++ = *s2++;

     }

while ( *s1 != 0 )  *d++ = *s1++;

while ( *s2 != 0 )  *d++ = *s2++;

*d = 0;

}

void  main( )

{  

char  s1[]="acmghn",s2[]="bcfhi",s3[20];

memset(s3,0,sizeof(s3));

merge(s3,sizeof(s3)-1,s1,s2);

puts(s3);

}

18. 输出结果:

char s1[]="acmghn", s2[]="bcfhi";
merge(s3, sizeof(s3)-1, s1, s2);
puts(s3);

输出:abccfghhi mn(合并成有序字符串)

(准确结果:abcfcmghhi

嵌入式笔试专栏 文章被收录于专栏

本专栏系统整理了嵌入式方向笔试中常见的知识点和高频考题,涵盖基础理论、常用算法、C语言陷阱、操作系统原理、驱动开发、常见外设通信协议(如 I2C/SPI/UART)、RTOS、Linux 内核、以及实用电路知识等内容。

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务