通信电子、嵌入式类面试题刷题计划03


突然接到个面试又是让明天就去…嵌入式软件开发/测试的实习岗位笔试打听了下主要考C语言期末难度和专业常识两年多没碰C了上一次用C主要还是大三课程设计读懂后把C改成51汇编哎临时突击一下吧。

021——“Hello, world!”

#include <stdio.h>  //标准库声明
int main()  //主函数
{
printf("Hello word!\n");  //输出Hello word!
return 0;  //返回
}

022——计算圆的面积

#include <stdio.h>

int radius, area;  //变量声明半径和面积 

int main()
{
	printf("Enter radius (i.e. 10):");
	scanf("%d", &radius);
	area = (int) (3.14159 * radius * radius);
	printf( "\n\nArea = %d\n", area);
	return 0;
}

023——打印10x10的星号

#include <stdio.h>

int x, y;

int main( void )
{
	 for ( x = 0; x < 10; x++, printf( "\n" ))
		 for ( y = 0; y<10; y++)
			 printf("* ");

		 return 0;
}
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *

024——字符串打印

#include <stdio.h>

int main( void )
{
	printf("keep looking!");
	printf("you\'ll find it!\n");  //单引号用\'表示
	//return 0;
}

025——打印26个英文字母

#include <stdio.h>

int main(void)
{
	int ctr;
	
	for( ctr = 65; ctr < 91; ctr++ )  //大写A从65开始
    	printf("%c ", ctr );
}
#include <stdio.h>

int main(void)
{
	int ctr;
	
	for( ctr = 97; ctr < 123; ctr++ )  //小写从97开始
    	printf("%c ", ctr );
}

026——strlen函数的用法

#include <stdio.h>
#include <string.h>  //引入头文件
int main()
{
	char arr[10] = "length";
	int num = strlen(arr);
	printf("数组arr的长度为%d\n", num);
 
	return 0;
}
数组arr的长度为6

【C语言】strlen()函数

<string.h>是C语言标准库中一个常用的头文件在使用到字符数组时需要使用主要包含以下函数

▪ strcpy
▪ strncpy
▪ strcat
▪ strchr
▪ strcmp
▪ strnicmp
▪ strlen
▪ strcspn
▪ strdup
▪ stricmp
▪ strerror
▪ strcmpi
▪ strncmp
▪ strncpy
▪ strnicmp
▪ strnset
▪ strpbrk
▪ strrchr
▪ strrev
▪ strspn
▪ strstr
▪ strtod
▪ strtok
▪ strtol
▪ strupr
▪ swab

027——sizeof函数的使用

/* sizeof.c - 显示C程序中变量类型的大小 */
/*            单位为字节*/

#include <stdio.h>

int main(void)
{
	printf("\nAn unsigned int     is %d bytes", sizeof(unsigned int));
	printf("\nAn int      is %d bytes", sizeof(int));
	printf("\nA short     is %d bytes", sizeof(short));
	printf("\nA long      is %d bytes", sizeof(long));
	printf("\nA long long is %d bytes", sizeof(long long));
	printf("\nAn unsigned char is %d bytes", sizeof(unsigned char));
	printf("\nAn unsigned int  is %d bytes", sizeof(unsigned int));
	printf("\nAn unsigned short is %d bytes",sizeof(unsigned short));
	printf("\nAn unsigned long is %d bytes", sizeof(unsigned long));
	printf("\nAn unsigned long long is%d bytes", sizeof(unsigned long long));
	printf("\nA float     is %d bytes", sizeof(float));
	printf("\nA double    is %d bytes\n", sizeof(double));
	printf("\nA long double is %d bytes\n", sizeof(long double));
	
	return 0; 
} 

An unsigned int     is 4 bytes
An int      is 4 bytes
A short     is 2 bytes
A long      is 4 bytes
A long long is 8 bytes
An unsigned char is 1 bytes
An unsigned int  is 4 bytes
An unsigned short is 2 bytes
An unsigned long is 4 bytes
An unsigned long long is8 bytes
A float     is 4 bytes
A double    is 8 bytes

A long double is 16 bytes

028——if else、变量赋值语句

#include <stdio.h>

int x, y; /*先定义变量x,y*/
int main(void)
{
	printf("Enter two numbers\n");
	scanf("%d, %d", &x, &y ); /*计算机底层只识别0和1scanf能将操作者输入的变量对应ASCII码转化为二进制储存在计算机中即变量地址*/
	
	if((x >= 1) && (x <= 20))
	{   y = x;
	    printf("%d", y); //如果x在1-20之间将x的值赋予y 
	}  /*if else语句中语句命令超过两句时要放在{}内*/
	else
	{   y = y;
	    printf("%d", y); // 否则保持y的原值不变 
	}
	
	return  0;
}
Enter two numbers
10 23
10

029——if else语句

#include <stdio.h>

int x = 2;
void main()
{
	if( x == 1 ) 
	  printf(" x equals 1");
	else
	  printf("x does not equal 1");
} 

030——if elseif else语句判断是否成年

#include <stdio.h>

int birth_year, age;

int main(void)
{
	printf("Enter the year you were born: ");
	scanf("%d", &birth_year);
	
	age = CURRENTYEAR - birth_year;
	
	if (age < 21)
	   printf("You are not a legal adult");
	else if((age >=21) && (age <= 65))
	   printf("You are a legal abult and not an old man") ;
	else
	   printf("You are an old man");
	
	return 0;      
 } 
Enter the year you were born: 2000
You are not a legal adult

031——冒泡排序

在这里插入图片描述

#include <stdio.h>
#define SIZE 10
int main()
{
	int a[SIZE] = {8,6,10,4,5,2,7,1,9,3};
	int i,j,t;
	for(i=0;i<10-1;i++)
	{
		for(j=0;j<10-1;j++)
		{
			if(a[j]>a[j+1])  //从小到大排序如果前一个大于后一个就交换
			{
				t = a[j+1];
				a[j+1] = a[j];
				a[j] = t;
			}
		}
	}
	printf("冒泡排序结果");
	for(i=0;i<10;i++)
		printf("%d ",a[i]);
	return 0;
}
冒泡排序结果1 2 3 4 5 6 7 8 9 10

032——选择排序

在这里插入图片描述

#include <stdio.h>
#define SIZE 10
int main()
{
	int a[SIZE] = {8,6,10,4,5,2,7,1,9,3};
	int i,j=0,t,k;
	for(i=0;i<9;i++)
	{
		k = i;
		for(j=i;j<10;j++)
		{
			if(a[j]<a[k])  //从小到大排序如果找到此趟最小的就交换
				k=j;
		}
		t = a[k];
		a[k] = a[i];
		a[i] = t;
	}
	printf("冒泡排序结果");
	for(i=0;i<10;i++)
		printf("%d ",a[i]);
	return 0;
}
选择排序结果1 2 3 4 5 6 7 8 9 10

033——堆和栈的区别

1、栈区存放函数的参数值、局部变量等由编译器自动分配和释放通常在函数执行完后就释放了其操作方式类似于数据结构中的栈。栈内存分配运算内置于CPU的指令集效率很高但是分配的内存量有限比如iOS中栈区的大小是2M。

2、堆区就是通过new、malloc、realloc分配的内存块编译器不会负责它们的释放工作需要用程序手动开辟内存和释放。 分配方式类似于数据结构中的链表。在iOS开发中所说的“内存泄漏”说的就是堆区的内存。

034——if(4 == a)和 if(a == 4)的区别【笔试】

没区别一般是使用 if(4 == a)因为常量不能赋值这样做的好处就是怕把if(a==4)漏写成if(a=4)

035——指针变量和普通变量的区别

普通变量系统会为变量分配地址变量值存放在地址中被使用时直接取值。
指针变量用于取一般变量的地址但其本身也有自己的地址。

#include <stdio.h>
int main() 
{
    int a = 100, b = 10;//定义整型变量ab并初始化
    int *p1, *p2;     //定义指向整型数据的指针变量p1p2
    p1 = &a;          //把变量a的地址赋给指针变量p1
    p2 = &b;         //把变量a的地址赋给指针变量p2
    printf("a=%d,b=%d\n", a, b);//输出变量a和b的值
    printf("p1=0x%x,p2=0x%x\n", p1, p2);  //指针变量p1,p2中存放的普通变量a,b的地址 
    printf("&p1=0x%x,&p2=0x%x\n", &p1, &p2);  //指针变量p1,p2自己的地址 
    printf("*p1=%d,*p2=%d\n", *p1, *p2);  //从指针变量中取值 
 	
    return 0; 
}
a=100,b=10
p1=0x62fe1c,p2=0x62fe18
&p1=0x62fe10,&p2=0x62fe08
*p1=100,*p2=10

面试感受

下午去面了13点半面到16点半笔试+面试+上机+面聊比想象的要顺利没有在笔试环节太过刁难上机是Excel-Bom两次f2f面聊offer应该是稳的数字Soc芯片方向的嵌入式软开应届希望能有机会在研发岗呆下去持续学习。
笔试编程是全英文考了道大端小端的编程题不会…还考了道字节转比特的也忘了太久没碰C了该好好拾起来了。

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6