NEW
Font size
WorksheetsKnow your basics in C?
Total questions: 20
Worksheet time: 13mins
The preprocessor can trap errors like missing declaration, nested comments or mismatch of braces.
True
False
What will be the output of the C program?
#include<stdio.h>
int main()
{
int 1_one = 25;
printf("%d",1_one);
return 0;
}
2
25
1
Compilation Error
According to MISRA C coding standards, is the following declaration correct?
static foo(void);
False
True
The fastest data access is provided using __________
Caches
DRAM’s
SRAM’s
Registers
Rule: There shall be no definitions of objects or functions in a header file.
Is this a valid rule according to MISRA ?
No
Yes
#include<stdio.h>
int main()
{
typedef static int *i;
int j;
i a = &j;
printf("%d", *a);
return 0;
}
Runtime error
0
Garbage value
Compiler error
Which of the below options is NOT compliant with MISRA C coding standards?
int16_t array1[5]={1,2,3,0,0};
int16_t array2[2][2]={0};
int16_t array3[2][2]={{0},{1,2}};
What does the following statement do?
x = x | 1 << n;
sets (n)th bit of x
sets (n+1)th bit of x
toggles (n+1)th bit of x
unsets (n)th bit of x
unsets (n+1)th bit of x
Which is not compliant with MISRA C coding standards?
if ( ( x > c1) && (y > c2) && (z > c3) )
if ( ( x > c1) && (y > c2) || (z > c3) )
if ( (x > c1) && (y > c2) )
As per MISRA C coding standards, C macros shall NOT expand to ________?
do-while-zero construct
storage class specifier
non-parenthesised expression
string literal
Whenever there is a conflict between a local variable and a global variable, which gets the priority?
local
global
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)
22
14
18
10
In C, parameters are always
Passed by value
Passed by reference
Non-pointer variables are passed by value and pointers are passed by reference
Passed by value result
Which of the following is true about return type of functions in C?
Functions can return any type
Functions can return any type except array and functions
Functions can return any type except array, functions and union
Functions can return any type except array, functions, function pointer and union
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);
}
Function is made globally available
extern means nothing, sum() is same without extern keyword
Function need not to be declared before its use
Function is made local to the file
In C, what is the meaning of following function prototype with empty parameter list
void fun()
{
/* .... */
}
Function can only be called without any parameter
Function can be called with any number of parameters of any types
Function can be called with any number of integer parameters.
Function can be called with one integer parameter.
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?
f(s, *s)
i = f(i,s)
f(i,*s)
f(i,*p)
The reason for using pointers in a Cprogram is
Pointers allow different functions to share and modify their local variables.
To pass large structures so that complete copy of the structure can be avoided.
Pointers enable complex “linked" data structures like linked lists and binary trees.
All of the above
Pick the correct statement for const and volatile.
const is the opposite of volatile and vice versa.
const and volatile can’t be used for struct and union.
const and volatile can’t be used for enum.
const and volatile can’t be used for typedef.
const and volatile are independent i.e. it’s possible that a variable is defined as both const and volatile.
In C, static storage class cannot be used with:
Global variable
Function parameter
Function name
Local variable
