0% found this document useful (0 votes)
9 views13 pages

Embedded C Exam

The document contains a series of multiple-choice questions related to C programming, covering topics such as function stack consumption, preprocessor directives, variable scopes, memory management, and embedded systems. Each question includes options with correct answers indicated. The document serves as a quiz or study guide for individuals looking to test their knowledge in C programming concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views13 pages

Embedded C Exam

The document contains a series of multiple-choice questions related to C programming, covering topics such as function stack consumption, preprocessor directives, variable scopes, memory management, and embedded systems. Each question includes options with correct answers indicated. The document serves as a quiz or study guide for individuals looking to test their knowledge in C programming concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

1.

The following affect the stack consumption of a function (you can choose more than one)
a.The number of function arguments..
b.The number of times the function called in the program.
c. The number of static local variables defined in the function.
d.The number of local variables defined in the code. e. The size of

the function code.

2.A segment of code is to be executed from RAM:

a. it is not possible to execute from RAM.

b.it is target dependent, but if it is possible, this segment of code should be copied to RAM after

each reset

c. it is target dependent, but if it is possible, this segment should be un- erasable in RAM.

d. it's possible no limitation.

3. Which of the following C Preprocessor constant declarations, for the

number of seconds in a calendar year.

a. #define SECONDS_PER_YEAR 60*60*24*365

b. #define SECONDS_PER_YEAR 60*60*24*365;

c. #define SECONDS_PER_YEAR (60*60*24*365UL)

d.#define SECONDS_PER_YEAR (60*60*24*365)

4. The following line "#define MAX_NUM 15" represents:

a.Integer Macro. b. Linker Constant.

c. Pre-Compiler Constant d. Preprocessor Macro.

5. One of the advantages of using Macros:

a. Decrease Code Size.

b. Increase Speed of execution.

c. Increase Portability.
6. Which of the following is the best way to declare a C preprocessor Macro that takes two
arguments and return the smaller of their two values?
a. #define MIN(A,B) ((A) < (B) ? (A): (B))
b. #define MIN(A,B) { if (A<B) A; else B; } x
c. #define MIN(A,B) ((A <B) ? A: B)
d. #define MIN(A,B) A<B? A: B;
7. Which of the following will define a function that can not be called from
another source file.
a. void function(){ ... } c. const void function (){ ... }
b. extern void function (){ ... } d.static void function (){ ... }
8. Which of the following items should be generally be declared using C volatile keyword (you
can choose more than one)
a.A memory mapped peripheral status register.
b. A global variable used within an interrupt service routine.
c. A global variable used by multiple tasks in a multi-thread application.
9. The static keyword can be used for
a. scope limitation. c. both answers.
b.persistent storage.
10.Static variables are:
a.Initialized once and retains its value through the program execution.
b. Can be accessed outside the scope of the function.
c. Disappear from the memory at end of the function.
11.A static variable is allocated in the ...
a.Data Segment. b. Stack. c. Heap.
12.Making the variable static affects:
a. its scope. b. its life-time.
c. Its scope and lifetime d. it depends.

18.To ensure the compiler will not perform any optimizations concerning the access of a
variable use the .... Keyword
a.extern b. register
c.volatile d. static
19. Using the... keyword informs the compiler of the variable type but does not allocate memory
for it.
a.extern b.register.
c. volatile d. static

20.Compilers used in Embedded Systems are:

a Cross Compilers. b. Native Compilers.

c. Answers A and B. d. None of the previous answers.


21.What will be the output of the following code

void func(){int i;}

int main(){ int y = 20; extern i; printf("%d",i);

{printf("%d",y);}

a.Compiler Error. b. Linker Error. c. 5 20

22.Inline function result in faster code execution and less code size:

a.TRUE. b. FALSE.

23. The #pragma is used to

a. define macros. b. remove code during pre-processing time.

c. Specify compiler and linker options.

24.In C programming, we have the following type of scopes:


a. Block scope. e. A and B
b. Function scope. f. A, B and C
c. File scope. g. A, B, C and D
d. Program scope.
25. The variable Port Register defined below is a:
int volatile * const PortRegsiter;
a PortRegsiter is a constant pointer to a volatile integer.
b. PortRegsiter is a pointer to a constant integer.
c. PortRegsiter is a pointer to a volatile integer.
d. const and volatile can not be used together.

26. What will be the output of this code:


#define u8Temp (6)

void main(){

#if u8Temp == 5 printf("Hello");

#elseif u8Temp == 6 printf("Hello1");

#else printf("Hello2"); #endif }

a. Hello1 b. Pre-Processor Error c. Hello2


27. The sizeof() operator is evaluated at:

a. Preprocessing Time. b.Linking Time. c. Run Time.

28. The tool that combines object files or libraries and produces a single

executable file is called:

a. Compiler. b. Assembler.

c. Pre-Processor. d. Linker.

29.Which of the following characteristics is primarily associated with software re-usability?


a.The extent to which the software can be used in other applications.
b. The extent to which the software can be used by many different users.
c. The capability of one system to be coupled with another system.

30.The following code will:


#define RW FLAG 0x1FFF7800
volatile uint32_t *flagAddress = NULL;
flagAddress = (volatile uint32_t *)RW_FLAG;
*flagAddress = 12;

a. The code will be compiled correctly. b.Segmentation Fault will occur.

c. The code will not compiled due to compilation error.

d. Garbage value will be stored in flagAddress.

31.To define an integer of size 4-bytes use:

a. short. b.long. c. int.

32. Which of the following is categorized as Asynchronous process?

a. A function that is called, performs the requests functionality and returns the result of the

request.

b. Interrupt Service Routine.

c. A function that is called, performs the requests functionality and returns without the result of

the request.

d.A schedule periodic function.


33.A reentrant function is a function that...

a. Calls itself.

b. Can be interrupted during its processing and then called again with another task.

c. Calls another function that calls it again.

d. Cannot be interrupted during its processing.

34.The difference between little- and big-endian bit orders is that ...
a. Little endian designates the MSB of a byte by bit7 while big endian designates it by bit 0

b. Little endian designates the MSB of a byte by bito while big endian designates it by bit 7

c. Little endian arranges the MSB of a byte on the right while big endian sets it on the left.

35.The #ifdef and #endif are used to...

a. define macros. b. remove code during pre-processing time.

c. specify compiler and linker options.

36. For the code below, select the correct answer.

#define NUMSTATICELS (pArray) (sizeof(pArray)/sizeof(*pArray))

a. The macro will not calculate the number of elements in the array.

b.The macro will work only with arrays statically defined in the code.

c. The macro will work only with arrays dynamically defined in the code.

37.0x12345678 is stored @ 0xFF000000 in the memory, which memory dump corresponds to it

(Assume Big Endian Architecture):

a. OxFF000000 12 34 65 78

b. 0xFF000000 00 00 00 00

c. OXFF000000 78 56 34 12
38.All is true about the keyword register except

a.it minimizes the load/store overhead. b.the compiler will never ignore it.

c. used with local variables and function arguments only.

39.Assume we have a macro defined as follows

#define(x) (!((x) & ((x)-1)))

and the input to the macro are of integral values only. This macro may

result in value that is

a.ZERO. b.1 c. Either 1 of the answers.

40. To protect the global u8Data variable in the following code, the code
should...
u8 u8Data;
interrupt void vid FctInterrupt(void){
u8Data++;

u8 u8Function(void){

u8 u8FinalValue;

u8Data = 0;

while(u8Data == 0);

u8Data <<=4;

u8Data++;

u8FinalValue=u8Data;

return u8FinalValue;

a. use a critical region in both vidFctInterrupt and u8Function.

b. use disable/enable interrupt in u8Function.

c. do nothing as there is no risk.


41.When writing a reentrant function, the function writer must ensure that he is not using

global nor static variables.

a.TRUE. b. False.

42.If x is an integer its size is not known at the moment, then the best way to initialize it to all 1's

is x = ...

a.~0 b. !0 c.0xFFFF

43. "Initialized variables" values are copied from ROM to RAM during:

a. Compilation. b. Linking.

c.Startup code execution. d. Reset.

44.One of the following is portable:

a. Integer type variables. b.Bit-fields usage.

c. All cases of using unions. d. No correct answer.

45.It is recommended to use the keyword goto in C programming:


a.False b.True
46.C constant variables exist in:
a. data segment. b.rodata segment.
C. constant segment. d. both b & c are correct.

47. static int sum =0;

int increment (int i){

sum += i;

return sum;}

The function above is:

a.not reentrant function. b. reentrant function.

c. static function.

d. The code will not be compiled due to compilation error.


48. What will be the output of the program?

#define SQR(x) (x*x)

int main(){

int a,b=3;

a = SQR(b+2); .

printf("%d\n",a);

return 0;

a. 25 b.11

c. Compilation Error. d. Run Time Error.

49. 2 variables can be swapped efficiently by:

a. 3 operations and a temp variable.

b. 3 operations without a temp variable.

c.Both of the answers. d. None of the answers.

50.Form this list, what is wrong regarding startup code?

a. Allocate space for and initialize the stack.

b. Initialize the stack pointer.

c. Call the main. d.Assign the program entry address.

51.Form this list, what is correct regarding startup code?


a. Allocate space for and initialize the stack.
b. Call the main.
c. Copy the initial values for initialized variables from ROM and RAM.
d. All of the above.
52. Which of the following is better?

A. #define mystruct struct A *

B. typedef struct A* mystruct;

Pick one of the choices:

a. A is better than B. b. Both are exactly the same.

c. B is better than A. d. Compiler Dependent.

53.If we want to define a variable within the body of a function such that it maintains its value

between function invocations, this variable should be

defined as:

a. auto. b. register.

c. volatile. d. static.

54.Assume size of char is 1 byte and size of int is 4 bytes.

struct x{

char y;

int z; }

a. Processor dependent. b.Compiler dependent.

c. Processor and compiler dependent. d. 5

55.If linker script is not provided to the linker:

a. Linking error happens.

b.The linker provides default linker script.

c. Code will be wrongly allocated.

d. None of the previous answers.


56. Which of the following is not a type of polling?

a.interrupts. b. tight.

c. occasional. d. periodic.

57.What is linkage of the function func1 if it is defined as follows:


static int func1 (int var)
{ return var * 2; }
a. Cannot be determined. c. External.
b.Internal. d. No Linkage.
58. What is the scope of the variable temp in the following code:
void swap (int *var1,int *var2){
if(*var2 != *var1){
int temp = *var1;
*var1 = *var2;
*var2 = temp; }
a. Local Scope. b. Function Scope.
c. Block Scope. d.Code will not compile.
59.In an embedded system with large number of activities must respond rapidly to an external
event E, which one of the following synchronization mechanisms should be used to notify the
program of an occurrence of E:
a. Periodic polling. c. Tight polling (busy-wait)

b. Occasional polling. d.Interrupt handling.

60.Why modular design is needed?

a. To have flexibility in design.

b. To subdivide a system into smaller parts called sub-systems.

c. To reduce the validation cost. d. To achieve project's short-term objectives.

61. Which of the following can implement asynchronous process?

a. Static methods. b. Watchdogs.

c.Callbacks. d. Operator overloading.

62.What is true about heaps and stacks?


a. Heap is faster than stack.
b. Global variables are allocated in the heap.
c.When using heap, memory management should be handled by the developer.
d. Variables sizes are limited when using heap.
63. Which of the following is a good update of C99?

a. Macros can have variable arguments.

b.Variable declaration can be done everywhere in the code.

c. C++ comments are legal.

d. Multiple uses of a type qualifier ignored after the first occurrence.

64.Consider the following example in a 32-bit microcontroller:

Linker Script:

MEMORY{

dataBlock1: org = 0x40000000, len = 0x200

dataBlock2: org = 0x40000200, len = 0x300

SECTIONS {*(.myVars )} > dataBlock1

In C File: App.c

#pragma section DATA ".myVars"

unsigned int Var1;

unsigned int Var2;

The variable Var2 address in memory will be:

a. 0.40000000 b.0x40000200

c. 0x40000004 d. 0x40000204
1 A,b 21 B 41 A

2 B 22 A 42 A

3 C 23 C 43 C

4 D 24 G 44 D

5 B 25 A 45 A

6 A 26 C 46 D

7 D 27 A 47 A

8 A,b,c 28 D 48 B

9 C 29 A 49 C

10 A 30 A 50 D

11 A 31 B 51 D

12 D 32 C 52 C

13 D 33 B 53 D

14 D 34 A 54 C

15 A 35 B 55 A

16 D 36 B 56 A

17 A 37 C 57 B

18 C 38 B 58 C

19 A 39 C 59 A

20 A 40 C 60 B

61 c 62 c 63 b

64 c

You might also like