wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Refresh your basics - MISRA 2012

Total questions: 20

Worksheet time: 22mins

Name
Class
Date
1.

A project with unused type declarations is compliant or not with MISRA?

For example,


int16_t unusedtype ( void )

{

typedef int16_t local_Type;

return 67;

}

a)

Compliant

b)

Non-compliant

2.

The following macro example comes under

void use_macro ( void ) {

#define SIZE 4

#define DATA 3

use_int16 ( SIZE );

}

Assertion: A project containing unused macro declaration will lead to code

redundancy and unclear.

Reason: The unused macro will give an advisory action and leads to un-necessary memory space consumption

a)

The Assertion and the Reason are correct but the Reason is not the correct explanation of the Assertion.

b)

Both the Assertion and the Reason are correct and the Reason is the correct explanation of the Assertion.

c)

Our Assertion is true but the Reason is false.

d)

The statement of the Assertion is false but the Reason is true.

e)

Both the statements are false.

3.

The preprocessor will assume that the macro identifier has a value of zero if

a)

Macro identifier has been defined and not used in preprocessor directive

b)

Macro identifier has not been defined and used in preprocessor directive

c)

Macro identifier has been defined and used in preprocessor directive

4.

Unintentional removal of code occurs if the source line containing a // comment ends with which of the following character?

a)

\

b)

/

c)

*

d)

/*

5.

Which of the following is not compliant with MISRA?

a)

int16_t y[ 3 ][ 2 ] = { 1, 2, 0, 0, 5, 6 };

b)

int16_t y[ 3 ][ 2 ] = { { 1, 2 }, { 0 }, { 5, 6 } };

c)

int16_t y[ 3 ][ 2 ] = { { 1, 2 }, { 0, 0 }, { 5, 6 }

6.

Which of the following is NOT compliant with MISRA?

a)

( bool_t ) false

b)

( int32_t ) 3U

c)

( bool_t ) 3U

d)

( bool_t ) 0

7.

The MISRA Standard only allows which of the below to initialize all elements of an array or struct?

a)

{0u}

b)

{0}

8.

switch ( x == 0 )

{

case false:

y = x;

break;

default:

y = z;

break;

}


Is the above code by using a switch expression with boolean type compliant with MISRA?

a)

Compliant

b)

Non-compliant

9.

uint16_t func ( uin t16_t para1 )

{

return para1;

}


uint16_t x;

void discarded ( uint16_t para2 )

{

func ( para2 ); //Line 1

( void ) func ( para2 ); //Line 2

x = func ( para2 ); //Line 3

}


Which line is not compliant with MISRA?

a)

Line 1

b)

Line 2

c)

Line 3

10.

The result of an assignment operator should not be used.

Which satisfies the above rule?

a)

if ( ( 0u == 0u ) || ( bool_var = true ) )

b)

if ( ( 0u == 0u ) || ( bool_var == true ) )

11.

volatile int32_t i;

int32_t j;

size_t s;


Which of the following is NOT compatible with MISRA?

a)

s = sizeof ( j );

b)

s = sizeof ( j++ );

c)

s = sizeof ( i );

12.

Is it allowed to modify the loop counter in a for loop in the for loop body?

a)

Yes

b)

No

13.

Is it advised to use goto statements for our systems?

a)

Yes

b)

No

14.

All if … else if constructs shall be terminated with an else statement.

a)

True

b)

False

15.

Which is NOT compliant with MISRA?

a)

extern void g ( char c, const k );

b)

extern void g ( char c, const int16_t k );

c)

typedef void ( *pfv ) ( int16_t x );

16.

RULE: A function shall not be declared implicitly.

What kind of MISRA category does this rule fall under?

a)

Mandatory

b)

Advised

c)

Required

17.

What is the meaning of using extern before function declaration? For example following function sum is made extern,


extern int sum(int x, int y, int z)

{

return (x + y + z);

}

a)

Function is made globally available

b)

extern means nothing, sum() is same without extern keyword

c)

Function need not to be declared before its use

d)

Function is made local to the file

18.

In C, parameters are always by default

a)

Passed by value

b)

Passed by reference

c)

Non-pointer variables are passed by value and pointers are passed by reference

d)

Passed by value result

19.

According to MISRA C coding standards, is the following declaration correct?

static foo(void);

a)

False

b)

True

20.

Pick the correct statement for const and volatile.

a)

const is the opposite of volatile and vice versa.

b)

const and volatile can’t be used for struct and union.

c)

const and volatile can’t be used for enum.

d)

const and volatile can’t be used for typedef.

e)

const and volatile are independent i.e. it’s possible that a variable is defined as both const and volatile.