wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Know your basics in C?

Total questions: 20

Worksheet time: 13mins

Name
Class
Date
1.

The preprocessor can trap errors like missing declaration, nested comments or mismatch of braces.

a)

True

b)

False

2.

What will be the output of the C program?


#include<stdio.h>

int main()

{

int 1_one = 25;

printf("%d",1_one);

return 0;

}

a)

2

b)

25

c)

1

d)

Compilation Error

3.

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

static foo(void);

a)

False

b)

True

4.

The fastest data access is provided using __________

a)

Caches

b)

DRAM’s

c)

SRAM’s

d)

Registers

5.

Rule: There shall be no definitions of objects or functions in a header file.

Is this a valid rule according to MISRA ?

a)

No

b)

Yes

6.

#include<stdio.h>

int main()

{

typedef static int *i;

int j;

i a = &j;

printf("%d", *a);

return 0;

}

a)

Runtime error

b)

0

c)

Garbage value

d)

Compiler error

7.

Which of the below options is NOT compliant with MISRA C coding standards?

a)

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

b)

int16_t array2[2][2]={0};

c)

int16_t array3[2][2]={{0},{1,2}};

8.

What does the following statement do?

x = x | 1 << n;

a)

sets (n)th bit of x

b)

sets (n+1)th bit of x

c)

toggles (n+1)th bit of x

d)

unsets (n)th bit of x

e)

unsets (n+1)th bit of x

9.

Which is not compliant with MISRA C coding standards?

a)

if ( ( x > c1) && (y > c2) && (z > c3) )

b)

if ( ( x > c1) && (y > c2) || (z > c3) )

c)

if ( (x > c1) && (y > c2) )

10.

As per MISRA C coding standards, C macros shall NOT expand to ________?

a)

do-while-zero construct

b)

storage class specifier

c)

non-parenthesised expression

d)

string literal

11.

Whenever there is a conflict between a local variable and a global variable, which gets the priority?

a)

local

b)

global

12.

Consider the following C declaration

struct {

short s[5];

union {

float y;

long z;

}u;

} t;

Assume that objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment considerations, is (GATE CS 2000)

a)

22

b)

14

c)

18

d)

10

13.

In C, parameters are always

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

14.

Which of the following is true about return type of functions in C?

a)

Functions can return any type

b)

Functions can return any type except array and functions

c)

Functions can return any type except array, functions and union

d)

Functions can return any type except array, functions, function pointer and union

15.

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

16.

In C, what is the meaning of following function prototype with empty parameter list

void fun()

{

/* .... */

}

a)

Function can only be called without any parameter

b)

Function can be called with any number of parameters of any types

c)

Function can be called with any number of integer parameters.

d)

Function can be called with one integer parameter.

17.

Consider the following C program.


void f(int, short);

void main()

{

int i = 100;

short s = 12;

short *p = &s;

__________ ; // call to f()

}


Which one of the following expressions, when placed in the blank above, will NOT result in a type checking error?

a)

f(s, *s)

b)

i = f(i,s)

c)

f(i,*s)

d)

f(i,*p)

18.

The reason for using pointers in a Cprogram is

a)

Pointers allow different functions to share and modify their local variables.

b)

To pass large structures so that complete copy of the structure can be avoided.

c)

Pointers enable complex “linked" data structures like linked lists and binary trees.

d)

All of the above

19.

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.

20.

In C, static storage class cannot be used with:

a)

Global variable

b)

Function parameter

c)

Function name

d)

Local variable