Beijing MediaTek Embedded Software Engineer Written Test Questions and Analysis

Beijing MediaTek Embedded Software Engineer Written Test Questions and Analysis

  • Logical Questions

  • Non-Directional Selection

  • Fill-in-the-Blank Questions

  • Programming Questions

Logical Questions

1. Among the 70 scholars attending the coronavirus vaccine development seminar, there are 39 Asian scholars, 33 PhDs, and 4 non-Asian scholars without a PhD. Based on the above statements, how many Asian PhDs are attending this seminar?

A 1

B 2

C 6

D 7

E 8

C

There are 39 Asian scholars, 33 PhDs, and 4 non-Asian scholars without a PhD, which adds up to 76 people, but the actual total is only 70. The concepts of Asian scholars and PhDs overlap, and both are completely distinct from non-Asian scholars without a PhD. This indicates that there are 6 Asian PhDs.

Alternatively, we can solve it using an equation. Let x be the number of Asian PhDs, then we can set up the equation: 31 + 33 – x + 4 = 70. Solving this equation gives: x = 6.

2. Women and children account for 2/3 of the total population in a certain province. If women refer to all female populations and children refer to all minors, and the number of males and females is equal in any age group, which of the following conclusions can be drawn from the above statement?

A The number of adult males and children in the province is equal.

B The number of adult males in the province is greater than the number of children.

C The number of adult males in the province is less than the number of children.

D The number of adult females and male children in the province is equal.

E The number of adult males and female children in the province is equal.

A

From the problem statement, we can derive the following table:

Female Male
Adult 1/3 1/3 2/3
Children 1/6 1/6 1/3
1/2 1/2

Since the number of males and females is equal in any age group, the total population is also equal in gender.

Since women and children account for two-thirds of the total population, adult males account for one-third.

Since adult males account for one-third, male children account for one-sixth (because males account for one-half).

Since male children account for one-sixth, female children also account for one-sixth. Therefore, the number of adult males and children in the province is equal.

3. There are 25 participants in a discussion meeting, and it is known that (1) at least 7 young teachers are male, (2) at least 8 male teachers are middle-aged, and (3) at least 10 young males are teachers; if two of the above three statements are true and one is false, which of the following can be concluded about the participants?

A There are at least 10 young teachers.

B There are at most 15 male teachers.

C All young males are teachers.

D There are at least 7 young males.

D

[1]: At least 7 young males [2]: At least 8 middle-aged males [3]: At least 10 young males.

[1] and [3] have overlapping quantities; if [3] is true, then [1] must also be true; if [1] is false, then [3] must also be false. This would contradict the condition of two truths and one falsehood, so [1] must be true.

Since [1] is true, there are at least 7 young male teachers, so there are at least 7 young males.

4. A certain traditional Chinese medicine formula has the following requirements: (1) If there is herb A, then there is no herb B; (2) If there is no herb C, then there must be herb D; (3) Ginseng and Gastrodia cannot both be present; (4) If there is no herb A but there is herb C, then ginseng is required. If Gastrodia is also present, which of the following statements about the formula is true?

A Contains herb A.

B Contains herb C.

C Does not contain herb C.

D Contains herb B or does not contain herb D.

No correct answer.

From “contains Gastrodia” and (3), we can conclude that ginseng is not included; thus, from (4), negating the consequent allows us to negate the antecedent, leading to either herb A is present or herb C is absent.

If herb A is present, from (1) we can conclude that herb B is absent; if herb C is absent, from (2) we can conclude that herb D is present; hence, either herb B is absent or herb D is present.

Therefore, there is no correct answer among the options.

5. A certain country plans to import several of the six crops: A, B, C, D, E, and F, for its large animal feed industry. Considering that some of these crops may contain prohibited ingredients, as well as their complementary or substitutable factors, the country has the following requirements for importing these crops: (1) All those without prohibited ingredients will be imported. (2) If A or B contains prohibited ingredients, then C and D will be imported. (3) If E contains prohibited ingredients, then F will not be imported; if C is imported, then B and F will also be imported. (4) If F is not imported, then E will be imported; if F is imported, then E will not be imported. Based on the above requirements, which of the following crops can be imported by the country?

A A, B, C

B B, C, D

C A, B, E

D A, B, F

E C, E, F

C

Option A contradicts (2).

Option B contradicts (2).

Option D contradicts (3).

Option E contradicts (4).

Non-Directional Selection

1. int i = 1; const int j = 2; which of the following statements is incorrect?

A const int *p1 = &i;

B const int *p2 = &j;

C int *const p3 = &i;

D int *const p4 = &j;

D

int *const p4 means p4 is a constant pointer, the memory location pointed to by p4 cannot be changed, but the value stored at that memory location can be changed. Since j is a constant, its value cannot be changed.

After assigning the address of j to p4, p4 can perform other operations (e.g., *p4 = 4;), which would change the value of j, thus int *const p4 = &j; is incorrect.

2. Which of the following statements about memory is correct?

A RAM is volatile memory that loses its stored content when power is off, while ROM is non-volatile memory that retains its content when power is off.

B The data bandwidth of memory is related to the memory’s data transfer frequency, data bus width, and memory size.

C User processes typically can only access virtual addresses in user space and cannot access virtual addresses in kernel space.

D In Linux, the buddy system algorithm is used to manage page-out memory fragmentation, while the slub algorithm is used to manage page-in memory fragmentation.

ACD

B: The formula for calculating memory data bandwidth is: data bandwidth = memory data transfer frequency × memory data bus width / 8.

3. Which of the following events can lead to process creation?

A System initialization

B fork system call

C pthread_create function call

D Initialization of a batch job

ABD

There are various ways to create processes, but all require an operating system to manage them. As long as there is an operating system, the concept of processes exists, and there must be ways to create processes. Some operating systems are designed for a single application, such as a vacuum robot; once started, all processes already exist.

For general systems (running many applications), there needs to be the ability to create or terminate processes during system operation, mainly divided into four forms of creating new processes:

1. System initialization (view processes using the ps command in Linux, or Task Manager in Windows; foreground processes interact with users, while background processes are unrelated to users, running in the background and only waking up when needed, called daemon processes, such as email, web pages, news, printing).

2. A process creates a child process during its execution (e.g., nginx creates multiple processes, os.fork, etc.).

3. User interactive requests that create a new process (e.g., when a user double-clicks any software, QQ, WeChat, etc.).

4. Initialization of a batch job (only applicable in large-scale batch processing systems).

Regardless of which method, the creation of a new process is executed by an existing process making a system call to create a process.

4. Which of the following statements are correct?

A Computer architecture is a discipline that studies the structure of computer system software.

B Modern computer processor architecture can be divided into complex instruction set computers and reduced instruction set computers based on storage methods.

C The biggest difference between RISC technology and CISC is the simplification of CPI.

D Single instruction stream single data stream computers execute at most one instruction per machine cycle.

CD

A. Computer architecture mainly studies software, hardware function allocation, and the determination of software and hardware interfaces.

B. Modern computer processor architecture can be divided into instruction system types, into complex instruction set computers and reduced instruction set computers.

5. The output of the following program in a 32-bit system is

//Parameter passing degenerates to pointer
void Func(char str_arg[100])
{
 printf("%d\n",sizeof(str_arg));
}
int main()
{
 char str[] = "Hello";
 printf("%d\n",sizeof(str));
 printf("%d\n",strlen(str));
 char *p = str;
 printf("%d\n",sizeof(p));
 Func(str);
 return 0;
}

A 5 5 4 4

B 6 5 4 4

C 6 5 6 4

D 5 5 5 100

B 6 5 4 4

When using the function strlen() to find the length of a string, the null terminator ‘\0’ is not included.

However, when using sizeof() to find the memory space occupied by a string, the null terminator ‘\0’ is included.

6. The following program will have what issues?

#include<stdio.h>
void my_alloc(char **p)
{
    *p = (char *)malloc(100);
}
int main()
{
    char *otr = NULL;
    char *ptr = NULL;
    my_alloc(&ptr);
    strcpy(ptr,"hello world");
    printf("%s\n",ptr);
    return 0;
}

Memory leak; the memory allocated to other variables will decrease. When we delete a pointer, the compiler will only free the memory space pointed to by that pointer, not the pointer itself. At this point, p becomes a dangling pointer.

Extension:

What does free() actually release?

free() releases the memory pointed to by the pointer! Note that it releases memory, not the pointer.

A pointer is a variable that is only destroyed when the program ends. After freeing the memory space, the pointer that originally pointed to this space still exists, but now the content pointed to by the pointer is garbage, which is undefined, hence it is called garbage.

Therefore, after freeing memory, set the pointer to NULL to prevent it from being dereferenced accidentally later. Of course, specific situations need specific analysis and solutions.

For example, if you define a pointer, allocate memory in a function, and then pass it to that pointer, then perhaps the task of freeing this memory should be left to other functions.

Where does malloc() actually get memory space?

It gets space from the heap. This means that the pointer returned by the function points to a block of memory in the heap. The operating system maintains a linked list of free memory addresses. When the operating system receives a program’s request, it traverses this list to find the first heap node with space larger than the requested space, then removes that node from the free list and allocates that space to the program.

7. Correct the errors in the program

The following program will cyclically right shift the array elements, with the array size, elements, and number of shifts specified by keyboard input. For example, for the array {1,2,3,4,5,6}, cyclically right shifting three positions results in {4,5,6,1,2,3}.

Please correct the errors in the program so that it can produce the correct result. Note: Do not change the structure of the program (there are four errors in total).

#include<stdio.h>
#include<stdlib.h>
void shift_func(int *array, int len, int k)
{
 int i = 0, j = 0;
 int temp = 0;
 if (array == NULL)
  return;
 k %= len;
 for (i = 0; i < k; i++)
 {
  temp = array[len - 1];
  for (j = len; j > 0; j--)
  {
   array[j] = array[j - 1];
  }
  array[0] = temp;
 }
}
int main()
{
 int len = 0, k = 0, i = 0;
 int *array = NULL;

 scanf("%d%d", &len, &k);
 array = (int*)malloc(len * sizeof(int*));
 if (array == NULL)
  return -1;
 printf("input the array\n");
 for (i = 0; i < len; i++)
  scanf("%d", array[i]);

 shift_func(array, len, k);

 printf("after shift the array is:\n");
 for (i = 0; i < len; i++)
  printf("%d", array[i]);
 printf("\n");

 return 0;
}

The modified program is as follows:

void shift_func(int *array, int len, int k)
{
 int i = 0, j = 0;
 int temp = 0;
 if (array == NULL)
  return;
 k %= len;
 for (i = 0; i < k; i++)
 {
  temp = array[len - 1];
  for (j = len; j > 0; j--)
  {
   array[j] = array[j - 1];
  }
  array[0] = temp;
 }
}
int main()
{
 int len = 0, k = 0, i = 0;
 int *array = NULL;

 scanf("%d%d", &len, &k);
 array = (int*)malloc(len * sizeof(int)); //array = (int*)malloc(len * sizeof(int));
 if (array == NULL)
  return -1;
 printf("input the array\n");
 for (i = 0; i < len; i++)
  scanf("%d", &array[i]); //scanf("%d", &array[i]);

 shift_func(array, len, k);

 printf("after shift the array is:\n");
 for (i = 0; i < len; i++)
  printf("%d", array[i]);
 printf("\n");
       
    // free(array);
    // array = NULL;
 return 0;
}

Programming Questions

Input year, month, and day, and calculate which day of the year it is. A year is considered a leap year if it meets either of the following two conditions:

1. The year is a multiple of 4 but not a multiple of 100.

2. The year is a multiple of 400.

Input description:

The input format for the date is: Year, Month, Day, containing three integers: year (1 <= Year <= 3000), month (1 <= Month <= 12), day (1 <= Day <= 31)

Thought process: A relatively easy method is to use a lookup table. Store the number of days in each month of the year in an array, with the array index representing the month.

It is important to note the handling of leap years. For convenience, we define two arrays, one for the number of days in leap years and one for non-leap years. We also define a variable flag to determine if it is a leap year. The specific code is as follows:

/*
 * @Description: Beijing MediaTek Embedded Software Engineer Written Test Questions
 * @Version: 
 * @Author: Embedded and Linux Matters
 * @Date: 2021-3-15 22:24:12
 * @LastEditors: Embedded and Linux Matters
 * @LastEditTime: 2021-3-15 22:39:41
 */
#include<stdio.h>
// Two arrays, storing the number of days in leap years and non-leap years for each month, corresponding to January to December
int b1[12]= {31,28,31,30,31,30,31,31,30,31,30,31};
int b2[12]= {31,29,31,30,31,30,31,31,30,31,30,31};

/**
 * @Description: Accumulate days
 * @Param: months, month. flag, leap year judgment flag
 * @Return: days
 * @Author: WeChat Official Account【Embedded and Linux Matters】
 */
int add(int months,int flag)
{
    int i,j = 0;
    if(flag)
    {
        for(i=0; i<months; i++)
        {
            j+=b2[i];
        }
    }
    else
    {
        for(i=0; i<months; i++)
        {
            j+=b1[i];
        } 
    }
    return j;
}

int main()
{
    int years,months,days;
    // Set flag to determine leap year
    int flag = 0;
    scanf("%d,%d,%d",&years,&months,&days);
    
    if(years>=1 && years<=3000 && months>=1 && months<=12 && days>=1 && days<=31)
    {
        if((years%4==0&&years%100!=0) || (years%400==0))
        {
            flag = 1;
        }
        printf("result is %d",add(months,flag));
    }
    else
    {
        printf("invalid parameter");
    }
    return 0;
}
Beijing MediaTek Embedded Software Engineer Written Test Questions and Analysis

1

“Review of 14 Mainstream Embedded Operating Systems, How Many Do You Recognize?”

2

“Source Code Attached | PS2 Remote-Controlled Car Based on STM32”

3

“Strange | Why Do Spacecraft and Missiles Prefer Microcontrollers Instead of Embedded Systems?”

Beijing MediaTek Embedded Software Engineer Written Test Questions and AnalysisBeijing MediaTek Embedded Software Engineer Written Test Questions and AnalysisShare this postBeijing MediaTek Embedded Software Engineer Written Test Questions and AnalysisLike this postBeijing MediaTek Embedded Software Engineer Written Test Questions and AnalysisSee this post

Leave a Comment