wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

OCS752_CP_MODEL 1_PART B (16.10.2020)

Total questions: 10

Worksheet time: 10mins

Name
Class
Date
1.

What is the output of this C code?


int main()

{

int i = 97, *p = &i;

foo(&p);

printf("%d ", *p);

return 0;

}

void foo(int **p)

{

int j = 2;

*p = &j;

printf("%d ", **p);

}

a)

2 2

b)

2 97

c)

Undefined behaviour

d)

Segmentation fault/code crash

2.

What is the output of this C code?


void main()

{

int k = 5;

int *p = &k;

int **m = &p;

printf("%d%d%d\n", k, *p, **m);

}

a)

5 5 5

b)

5 5 junk value

c)

5 junk value

d)

Run time error

3.

Consider the following C-program:

filter_none

edit

play_arrow

brightness_4

double foo (double); /* Line 1 */ int main() { double da, db; // input da db = foo(da); } double foo(double a) { return a; }

The above code compiled without any error or warning. If Line 1 is deleted, the above code will show:

a)

no compile warning or error

b)

some compiler-warnings not leading to unintended results

c)

some compiler-warnings due to type-mismatch eventually leading to unintended results

d)

compiler errors

4.

Output of following program?


#include<stdio.h>

void dynamic(int s, ...)

{

printf("%d ", s);

}

int main()

{

dynamic(2, 4, 6, 8);

dynamic(3, 6, 9);

return 0;

}

a)

2 3

b)

Compiler Error

c)

4 3

d)

3 2

5.

What is the output printed by the following program?

#include<stdio.h>

int f(int n, int k)

{

if (n == 0)

return 0;

else if (n % 2)

return f(n/2, 2*k) + k;

else return f(n/2, 2*k) - k;

}

int main ()

{

printf("%d", f(20, 1));

return 0;

}

a)

5

b)

8

c)

9

d)

20

6.

Consider the following C function

void swap ( int x, int y )

{

int tmp;

tmp = x;

x= y;

y = tmp;

}

In order to exchange the values of two variables a and b:

a)

Call swap (a, b)

b)

Call swap (&a, &b)

c)

swap(a, b) cannot be used as it does not return any value

d)

swap(a, b) cannot be used as the parameters passed by value

7.

Consider the following declaration :

struct addr {

char city[10];

char street[30];

int pin ;

};


struct {

char name[30];

int gender;

struct addr locate;

} person , *kd = &person ;


Then *(kd -> name +2) can be used instead of

a)

person.name +2

b)

kd -> (name +2 )

c)

*((*kd).name + 2 )

d)

either (A) or (B), but not (C)

8.

What is the output of this program?

#include <stdio.h>

struct

{

int i;

float ft;

}decl;

int main(){

decl.i = 4;

decl.ft = 7.96623;

printf("%d %.2f", decl.i, decl.ft);

return 0;

}

a)

4 7.97

b)

4 7.96623

c)

Compilation error

d)

None of the above

9.

The correct syntax to access the member of the ith structure in the array of structures is?

struct temp

{

int b;

}s[50];

a)

s.b.[i];

b)

s.[i].b;

c)

s.b[i];

d)

s[i].b;

10.

A short integer occupies 2 bytes an, ordinary integer 4 bytes and a long integer occupies 8 bytes of memory

If a structure is defined as

struct TAB{

short a;

int b;

long c;

}TABLE[10];

the the total memory requirement for TABLE is

a)

14

b)

140

c)

40

d)

32