Embedded C MCQs

Embedded C MCQs

Our team has conducted extensive research to compile a set of Embedded C MCQs. We encourage you to test your Embedded C knowledge by answering these 80 multiple-choice questions provided below.
Simply scroll down to begin!

1: How many bits are used by the watchdog timer in the SFRs for interrupt control?

A.   One

B.   Two

C.   Three

D.   None of the above.

2:

Fill in the blank:

A connected graph is said to be an Eulerian graph, only if all the vertices of the graph have _______ degree.


A.  

an odd 

B.  

an even

C.  

either an even or an odd 

3:

What will be the output of the following program?

#include <stdio.h>

void abc(int num1[], int size)

{

  int a = 0, b = size–1;

  while (a < b)

  {

while (num1[a] == 0 && a < b)

a++;

while (num1[b] == 1 && a < b)

b––;

if (a < b)

{

  num1[a] = 0;

  num1[b] = 1;

  a++;

  b––;

}

  }

}

int main()

{

  int num[] = {1, 0, 1, 0, 1, 0, 1, 1, 0};

  int z = 9, x = 0;

  abc(num, z);

  for (x = 0; x < 9; x++)

  printf("%d ", num[x]);

  getchar();

  return 0;

}


A.  

1 0 1 0 1 0 1 0 1 

B.  

1 1 0 0 1 1 0 0 1

C.  

 0 0 0 0 1 1 1 1 1 

D.  

1 1 1 1 1 0 0 0 0

4:

The following program is based on a recursive algorithm. Analyze the code and choose the correct output from the given options.

#include<stdio.h>

main( )

{ static int a,f;

a=5.2; f=1;

f = res( a ) ;

f++;

printf ( "%d", f++ ) ;

}

res ( int x )

{ static int f ;

if ( x == 1 )

return ( 1 ) ;

else

f = x/4.5 + x + res ( x – 1 ) + 2 ;

return ( f++ ) ;

}


A.  

21 

B.  

22

C.  

25 

D.  

27

5: The declaration int (*p[5])() means:

A.   p is an array of pointers to functions the return type of which is an integer

B.   p is a pointer to a function that returns a pointer to an integer

C.   p is a pointer to an array of integers

D.   p is a pointer to an array of integer pointers

E.   p is a pointer to a character string

6:

Which of the following statements are correct about watchdog timers?

i) All watchdog timers can only be programmed for a single time-out delay at a time.

ii) When watchdog timers time-out, they may either reset the processor or execute an interrupt.

iii) The hardware implementation of a watchdog timer depends on the processor.


A.  

Only statements i) and ii) are correct. 

B.  

Only statements ii) and iii) are correct. 

C.  

Only statements i) and iii) are correct.

D.  

All statements i), ii) and iii) are correct.

7: Which of the following bits are used in the Interrupt Enable Register 1 (IE1) of the watchdog timer register?

A.   NMI interrupt enable (NMIIE)

B.   Watchdog timer interrupt enable (WDTIE)

C.   NMI interrupt flag (NMIIFG)

D.   Watchdog timer interrupt flag (WDTIFG)

8: In relation to watchdog timer registers, which of the following is the correct bit range used by WDTPW (watchdog timer password)?

A.   Bits 7-3

B.   Bits 9-4

C.   Bits 11-7

D.   Bits 15-8

9: What is the checksum size (width) for CCITT algorithm?

A.   8 bits

B.   16 bits

C.   32 bits

D.   64 bits

10: Which of the following options is used for reusing the 16-bit pseudo index register, __longIX, created earlier by the compiler?

A.   long int exampleVar @ _ _longIX;

B.   long int @ _ _longIX, exampleVar;

C.   long int exampleVar $ _ _longIX;

D.   long int $ _ _longIX, exampleVar;

11:

In relation to the embedded C malloc() function, which of the following is the correct syntax for defining a header block with name hExample?


A.  

 typedef struct Header hExample {


 struct *ptr;


 unsigned int size;


}   


B.  

typedef hExample {

 struct *ptr hExample;

 unsigned int size;

} HEADER; 


C.  

typedef struct hExample {

 struct hExample *ptr;

 unsigned int size;

} HEADER; 


D.  

None of the above.

12:

What would be printed on the standard output as a result of the following code snippet?

char i = 'A';

char *j;

j = & i;

*j = *j + 32;

printf("%c",i);


A.  

An error will occur 

B.  


C.  

A

D.  

b

E.  

c

13: In the Harvard architecture of computers, how many data buses are used for accessing data and instructions?

A.   Only one.

B.   Only Two.

C.   Two or more.

14:

Choose the correct methods/techniques from the following options that can be used to design algorithms.

1. Divide and conquer

2. Greedy method

3. Back tracking

4. Branch and bound


A.  

Only 1 and 2

B.  

Only 1, 2 and 3  

C.  

Only 1, 2 and 4 

D.  

1, 2, 3 and 4   

15:

Consider the following code.

int i = 4, *j, *k;

Which one of the following statements will not work?


A.  

j = &i; 

B.  

j = j + 4;

C.  

j = j - 2;

D.  

k = j + 3; 

E.  

j = j * 2; 

16: In relation to National Semiconductor COP888 assembly language, which of the following is the correct syntax of the instruction that is used for executing the next instruction, on the condition that the bit 6 of register B is 1?

A.   IFBIT 06,[B]

B.   IFBIT 1,[B,06]

C.   IFBIT 06,[1,B]

D.   IFBIT 1,06,[B]

17:

This question is based upon the figure shown below

Which of the given images represents a correct binary search tree, if the elements are inserted in the following order?

6, 31, 3, 41, 26, 5


A.  

1

B.  

2

C.  

3

D.  

None of the above

18: In relation to the watchdog timer register (WDTCTL), which of the following values for WDTISx bits signifies watchdog clock source, /512?

A.   00

B.   01

C.   10

D.   11

19:

What function will the following code perform?

void delete_element ( node *m, int n)

{

node *p, *k;

k = search ( m, n);

if (k = = ( node *) NULL)

return;

p = k –> next;

k –>next = p –>next;

free (p);

}


A.  

It will delete an element from the beginning of the list.

B.  

It will delete an element from the end of the list.

C.  

It will delete the element that is next to a given element in the list.

20: In relation to watchdog timer operations, setting the WDTTMSEL bit to which of the following options results in selecting the interval timer mode?

A.   0

B.   1

C.   2

D.   11

21:

Which of the following statements is/are valid and correct?

1.char amessage[] = "lmnop";

amessage++;

2.char *pmessage = "abcde";

(*pmessage)++;

3.char amessage[] = "lmnop";

(*amessage)++;

4.char *pmessage = "abcde";

pmessage++;


A.  

1234 

B.  

23

C.  

24

D.  

14 

E.  

34 

22:

This question is based upon the figure shown below

The given program, which was supposed to give output as shown in the image, has some errors. Analyse the code and choose the correct line number(s) containing error(s).

1.int main( )

2.{ int i=1,j=1,k=1;

3. abc(i,j,k);

4. xyz(i,j,k);

5. return 0;

6.}

7.abc (int a, int b, int c)

8.{ for(;a<=5;a++)

9. { for(b=5;b>a;b--)

10.    { printf(" "); }

11.    for(c=1;c<=a;c++)

12.    { printf("* "); }

13.    print("\n");

14. } }

15.xyz(int *a, int *b, int *c)

16.{ for(a=4;a>=1,a--)

17. { for(b=4;b>=a;b--)

18.    { printf(" "); }

19.    for(c=a;c>=1;c++)

20.    { printf("* "); }

21.    printf("\n");

22. } }

a. 4

b. 9

c. 13

d. 14

e. 15

f. 16

g. 17

h. 19

Given the array:

int num[3][4]= {

                {3,6,9,12},

                {15,25,30,35},

                {66,77,88,99}

                };

what would be the output of *(*(num+1)+1)+1?


A.  

3

B.  

15

C.  

26

D.  

66

E.  

77

23: Which of the following divisors (polynomial) is used by the cyclic redundancy check algorithm CRC16?

A.   0x8005

B.   0x1021

C.   0x8801

D.   0x2100

24: What is the erase size for the EPROM memory?

A.   byte.

B.   sector

C.   Entire chip.

D.   None of the above.

25:

Which of the given functions will be performed by the following program?

#include <stdio.h>

void main()

{

int arr1[15];

int a, b, number1, tmp_no;

printf("Enter any value between 2 and 15\n");

scanf("%d", &number1);

printf("Enter elements\n");

for (a = 0; a < number1; a++)

{

    scanf("%d", &arr1[a]);

}

for (a = 0; a < number1; a++)

{

    for (b = 0; b < (number1 – a – 1); b++)

    {

        if (arr1[b] > arr1[b + 1])

        {

            tmp_no = arr1[b];

            arr1[b] = arr1[b + 1];

            arr1[b + 1] = tmp_no;

        }

    }

}

for (a = 0; a < number1; a++)

{

    printf("%d\n", arr1[a]);

}

}


A.  

It will sort and print the array in the ascending order, by using the merge sort. 

B.  

It will sort and print the array in the ascending order, by using the selection sort.

C.  

It will sort and print the array in the ascending order, by using the bubble sort.

D.  

It will sort and print the array in the ascending order, by using the quick sort.

26:

Given the array:

int num[3][4]=

{

{3,6,9,12},

{15,25,30,35},

{66,77,88,99}

};

what would be the output of *(*(num+1))?


A.  

3

B.  

15

C.  

66

D.  

6

E.  

25

27:

Analyse the following code and choose its correct output from the given options.

#include<stdio.h>

int main()

{

int num1[9] = {3,2,3,4,5,2,3,9,2};

int *pt1, sm=0;

int a, b, p, z, n=9;

z = n;

pt1 = num1;

for (a = 0; a < z; a++)

{

    for (b = 0; b < z; b++)

    {

        if (a == b)

        {

            continue;

        }

        else if (*(pt1 + a) == *(pt1 + b))

        {

            p = b;

            z--;

            while (p < z)

            {

                *(pt1 + p) = *(pt1 + p + 1);

                p++;

            }

            b = 0;

        }

    }

}

for (a = 0; a < z; a++)

{

    sm=sm+num1[a];

}

printf("%d",sm);

return 0;

}


A.  

22

B.  

23

C.  

24

D.  

25

28: How many memory spaces and data buses are used by the Von Neumann architecture?

A.   One common memory space and one data bus.

B.   One common memory space and two data buses.

C.   Two memory spaces and one data bus.

D.   Two memory spaces and two data buses.

29: If a full binary tree has a total of 63 nodes, then what will be the numbers of the internal nodes and the leaves, respectively, in the binary tree?

A.   31 and 32

B.   34 and 29

C.   33 and 30

D.   28 and 35

30: In relation to the watchdog timer register (WDTCTL), what will happen if the value of WDTCNTCL bit is set to 1?

A.   No action will be performed.

B.   It will clear the count value to 0000h.

C.   It will set the count value to 1000h.

D.   It will stop the watchdog timer.

31:

What would be printed on the standard output as a result of the following code snippet?

main()

{

char *pmessage = "asdfgh";

*pmessage++;

printf("%s", pmessage);

return 0;

}


A.  

Will result in Compilation Error

B.  

Undefined string

C.  

sdfgh 

D.  

asdfgh

32: What will happen if in data structure a pop operation on the stack causes the stack pointer to move past the origin of the stack?

A.   Overflow

B.   Underflow

C.   Null

D.   Garbage collection

33:

In relation to system reset and initialization, which of the following options can trigger the Power-Up Clear (PUC) signal?

i) The Power-On Reset (POR) signal.

ii) Security key violation of a flash memory.

iii) Security key violation of a watchdog timer.

iv) Expiration of a watchdog timer when in the watchdog mode only.


A.  

Only options i) and iii).

B.  

Only options i), ii) and iii).

C.  

Only options i), iii) and iv).

D.  

All options i), ii), iii) and iv). 

34:

What would be the output of the given C program?

int main( )

{

int a = 10, b = 20, m = 47, n = 96 ;

abc ( &a, &b ) ;

wxy ( &m, &n);

printf ( "%d, %d, %d, %d", a, b, m, n ) ;

return 0;

}

abc( int *x, int *y )

{

int t ;

t = *x ;

t = xyz();

*x = *y ;

*y = t++ ;

}

wxy(int *p, int *q)

{

*p = *p/2+9-1;

*q = *p/2+71-2;

}

xyz()

{

int t;

t = 6/2-54/3-(5.6/4);

return(t);

}


A.  

20, 10, 25, 64

B.  

20, -16, 31, 84

C.  

10, -20, 57, 35

D.  

10, -16, 20, 21

E.  

12, -16, 11, 24

35: In embedded C, which of the following functions is used for initializing the free-space pointer for indicating the first available byte of heap space?

A.   malloc()

B.   i_alloc()

C.   calloc()

D.   free()

36: In relation to watchdog timer registers, the WDTPW (watchdog timer password) is always read as which of the following options?

A.   05Ah

B.   06Ah

C.   069h

D.   059h

37: In relation to Interrupt Enable Register 1 (IE1) of the watchdog timer register, which of the following bits can be used by other modules?

A.   Bits 3-1

B.   Bits 5-2

C.   Bits 7-5

D.   Bits 7-4

A.   BIS.B

B.   BIC.B

C.   MOV.B

D.   CLR.B

39:

Which of the given types of memories has the following characteristics?

i) It requires a block-sized 'erase' operation before this type of memory can be programmed.

ii) It is used for the storage of a program code.


A.  

EEPROM 

B.  

Flash ROM

C.  

UV EPROM

D.  

PROM

40: Which of the following memory types has fast relative speed?

A.   SRAM

B.   EEPROM

C.   PROM

D.   Masked ROM

41:

Find the output of the following program and choose the correct answer from the given options.

#include <stdio.h>

#include <malloc.h>

void abc(int num2[], int num)

{

int *c = (int *)calloc(sizeof(int), (num – 2));

int i;

printf("output: ");

for (i = 0; i < num; i++)

{

    if (c[num2[i]] == 1)

    printf(" %d ", num2[i]+5);

    else

    c[num2[i]]++;

}

}

int main()

{

int num1[] = {15, 10, 10, 2, 7, 4, 2};

int af = sizeof(num1) / sizeof(num1[0]);

abc(num1, af);

getchar();

return 0;

}


A.  

output: 15 4

B.  

output: 15 7

C.  

output: 10 7

D.  

output: 10 2

42:

This question is based upon the figure shown below

Choose from the given image, the correct output of the following code.

#include<stdio.h>

main ()

{

int x[3][3], y[3][3];

abc(x);

xyz(x,y);

printa(y);

}

abc(m)

int m[][3];

{

int i, j;

for(i=0;i<3;i++)

{for (j=0; j<3;j++)

    {m[i][j]=((i+2) + (j+3));

    }}

}

xyz(x,y)

int x[][3], y[][3];

{

int i, j;

for(i=0;i<3;i++)

for (j=0;j<3;j++)

{

    y[j][i]=x[i][j];

}

}

printa(m)

int m[][3];

{

int i,j;

for(i=0;i<3;i++)

{

    for (j=0; j<3;j++)

    printf("%d ", m[i][j]);

    printf("\n");

}

}


A.  

(1) 

B.  

(2)

C.  

(3) 

D.  

(4)

43: Which of the following memory types is neither volatile nor writable?

A.   SRAM

B.   DRAM

C.   Masked ROM

D.   Flash

44: In relation to embedded C memory management, which of the following are incorrect minimum requirements for dynamic memory allocator?

A.   The free() function must prevent the fragmentation of freed memory.

B.   The order of calls to free() function must be exactly reverse of the order of calls to malloc().

C.   If no memory is available, an error condition must be returned.

D.   Overhead in memory need not to be minimized.

45: In relation to embedded C, which of the following data types is used for accessing the bit addressable memory of RAM (20h-2fh)?

A.   sbit

B.   bit

C.   SFR

D.   None of the above.

46:

What will be the output of the given program?

#include<stdio.h>

#include<stdlib.h>

struct node

{

  int data;

  struct node *next;

};

void ab(struct node* head)

{

  if(head == NULL)

  return;

  ab(head–>next);

  printf("%d ", head–>data*12);

}

void de(struct node* start)

{

  if(start == NULL)

  return;

  printf("%d ", start–>data);

  if(start–>next != NULL )

  de(start–>next–>next);

  printf("%d ", start–>data*7/6);

}

void p(struct node** head_ref, int new_data)

{

  struct node* new_node =(struct node*) malloc(sizeof(struct node));

  new_node–>data = new_data;

  new_node–>next = (*head_ref);

  (*head_ref) = new_node;

}

int main()

{

  struct node* head = NULL;

  p(&head, 15);

  p(&head, 333);

  p(&head, 31);

  p(&head, 21);

  p(&head, 17);

  ab(head);

  de(head);

  getchar();

  return 0;

}


A.  

180 3996 372 252 204 67 45

B.  

15 333 31 21 17 31 15 21 333 17

C.  

180 3996 372 252 204 17 31 15 17 36 19

D.  

15 333 31 21 17

47: In relation to microcontrollers, which of the following types of buses is/are bi-directional?

A.   Address bus.

B.   Data bus.

C.   Both options a and b.

D.   Neither option a nor b.

48:

What will be the output of the following program?

#include <stdio.h>

struct st1

{

int a;

struct st1 *ptr1 ;

};

main( )

{

struct st1 w1,w2;

w1.a = 251 ;

w2.a = 351 ;

w1.ptr1 = &w2 ;

w2.ptr1 = &w1 ;

printf ( "%d %d", w1.ptr1 –> a, w2.ptr1 –> a ) ;

}


A.  

251 251

B.  

351 351

C.  

251 351

D.  

351 251

49:


A.  

1

B.  

2

C.  

3

D.  

4

50: Which of the following statements is/are false about a pointer?

A.   A pointer allows to pass variables, strings, functions, arrays, and structures as function arguments.

B.   A pointer provides functions that can modify their calling arguments.

C.   A pointer variable holds the value as well as the memory address of another variable.

D.   A pointer does not allow to return structured variables from functions.

E.   A pointer supports dynamic allocation and de-allocation of memory segments.