wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

TECH - C

Total questions: 30

Worksheet time: 50mins

Name
Class
Date
1.

Which of the following declarations is/are correct for creating an “integer array of 5 elements”?

(Assume the size of integer to be 2 bytes)

a)

int *a = (int *)malloc(5);

b)

int **a = (int *)malloc(10);

c)

int a[] = (int *)malloc(10);

d)

int (*a)[5];

2.

What would be the output of the following program?

(Assume the size of integer to be 2 bytes)

char ch = ‘A’;

int a = ‘a’;

if(sizeof(ch) > ch - a){

printf(“YES!”);

}

else{

printf(“NO!”);

}

a)

YES!

b)

NO!

3.

What is the size(in bytes) of the following structure?

(Assume the size of integer to be 2 bytes)

struct Student{

int age;

int marks;

char class;

};

a)

7 bytes

b)

6 bytes

c)

8 bytes

d)

5 bytes

4.

Which of the following statements is FALSE?

a)

calloc() is slower compared to malloc()

b)

free() is used to remove unwanted heap memory

c)

There are 3 passing techniques in C:

i) Pass by Value ii) Pass by Reference

iii) Pass by Address

d)

We can use return statement in a function returning void

5.

Choose the correct conclusion for the following given program:

#include <stdio.h>

int main()

{

int x;

scanf("%d",&x);

if(x < 0){

printf("Undefined");

}

else{

int factorial = 1;

for(int i = 1; i<=x; i++){

factorial *= i;

}

printf("The factorial of %d is : %d",x,factorial);

}

return 0;

}

a)

The program correctly returns the factorial of any given number

b)

The program correctly returns the factorial of any number greater than 1

c)

The program correctly returns the factorial of any number greater than 0

d)

None of the above

6.

The following program finds the second maximum element in the array.

Which of the following statements should be the correct function definition for the function “calculate()” in the given program?

//modify the function definition below

___calculate(_______){

int sum = 0;

for(int i = 0; i<n; i++){

sum += (*arr)[i];

}

return sum;

}

a)

int calculate(int (*arr)[], int n)

b)

int calculate(int *arr[n])

c)

int calculate(int arr[n])

d)

int calculate(int *arr[], int n)

7.

Choose a correct statement about a Multidimensional array and pointer.?

a)

int *ptr[N] is an array of N integer pointers. Size is N * sizeof(1*int).

b)

int (*ptr)[N] is a pointer to an array of N elements. Size of ptr is size of 1 integer

c)

Both option A & option B.

d)

None of these

8.

Is it possible to write a C Program that prints “Hello World!” without using a statement terminator(;)? (Assume that you don’t need to write a return statement)

a)

Yes

b)

No

c)

Cannot Be Determined

9.

Which of the following statements is incorrect?

a)

We cannot dereference a void pointer

b)

A global and a local variable can have the same name

c)

The sizeof(x) function returns the size of ‘x’

d)

It is a good programming practice to set a dangling pointer to point to NULL

10.

What would be the value displayed by the printf() function in the following code snippet?

(Assume size of integer to be 2 bytes)

#include <stdio.h>

int main()

{

int a = 1;

int b = sizeof(a++);

printf("%d %d",b,a);

return 0;

}

a)

4 1

b)

4 2

c)

2 1

d)

Compiler Dependent

11.

printf("%d", scanf("%d", &num)); is a valid C statement.

a)

TRUE

b)

FALSE

12.

What should be the values of the variables ‘a’ and ‘b’ so that the following program produces an output “RCCIIT”?

int a = 5;

int b = 1;

if(a + b - (a/b) * b, ++a, --b){

printf("RCCIIT");

}

else{

printf("TIICCR");

}

a)

a = 0, b = 0

b)

a = 1, b = 0

c)

a = 1, b = 1

d)

Cannot Be Determined

13.

Consider the code fragment written in C below :

void f (int n)

{

if (n <=1) {

printf ("%d", n);

}

else {

f (n/2);

printf ("%d", n%2);

}

}

What does f(225) print?

a)

11100001

b)

11110001

c)

11110000

d)

11000011

14.

Which of the following is the correct way of declaring a variable?

a)

int alph@b3t = 5;

b)

float 34var = 4.7f;

c)

char strlen = 97;

d)

int default = 0;

15.

What would be the output of the following pseudocode?

a = 0;

if(a = 0){

if(++a){

print("Inside If");

}

else{

print("Inside Else")

}

}

else

print("Outside Else");

a)

Inside If

b)

Inside Else

c)

Outside Else

d)

Inside ElseOutside Else

16.

What does the following program return for fun(6) ?

int fun(int n){

if(n <= 1)

return 1;

else{

return n + n*fun(n--);

}

}

a)

720

b)

445

c)

Infinite Loop

d)

Stack Overflow

17.

How many function calls will be evaluated for fun(6) for the following program?

int fun(int n){

if(n <= 1)

return 1;

else{

return 5*fun(n-3) + 3*fun(n-2);

}

}

a)

8

b)

7

c)

45

d)

50

18.

Which of the following is not a primitive data type?

a)

Integer

b)

Float

c)

Character

d)

Pointer

19.

How many times will the following loop execute? (MARK 2)

int i,j;

i = 1;

j= 1;

for( ; i<=n; i = i+j, j++);

a)

sqrt(n)

b)

log(n)

c)

n/2

d)

loglog(n)

20.

What is the correct description for the variable fun declared below?

int *(*fun)(int **)

a)

fun is a function that takes a pointer to a pointer to integer as argument and returns a pointer to a pointer to integer

b)

fun is a pointer to a function that takes a pointer to a pointer to integer as argument and returns a pointer to integer

c)

. fun is a pointer to a function that takes a pointer to integer and returns a pointer to pointer to integer

d)

. fun is a function that takes a pointer to integer and returns a pointer to integer

21.

what will be the output of the below program?

#include <stdio.h>

int main()

{

int x = 2;

switch (x) {

x--;

switch (x) {

case 1:

printf("CSE");

break;

case 2:

printf("DEPARTMENT");

break;

case 3:

printf("INNOVISION");

break;

default:

printf(“2021”);

}

}

return (0);

}

a)

CSE

b)

DEPARTMENT

c)

No Output

d)

INNOVISION

22.

If malloc() and calloc() are not type casted, the default return type is ___________

a)

void*

b)

void**

c)

int*

d)

char*

23.

If the space in memory allocated by malloc is not sufficient, then an allocation fails and returns ___________

a)

NULL pointer

b)

Zero

c)

Garbage value

d)

The number of bytes available

24.

Loss in precision occurs while typecasting from____________

a)

char to short

b)

float to double

c)

long to float

d)

float to int

25.

Output Will be:

#include <stdio.h>

int main(){

int x = 2, i = 0;

do {

x = x++;

i++;

} while (i != 3);

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

}

a)

Undefined behaviour

b)

Output will be 3

c)

Output will be 6

d)

Output will be 5

26.

Which return type cannot return any value to the

calling function?

a)

int

b)

float

c)

void

d)

double

27.

Which operator is used to dereference a pointer?

a)

&

b)

*

c)

–>

d)

None of these

28.

The __ operator informs the compiler that the variable is a pointer variable.

a)

&

b)

*

c)

Both

d)

None Of These

29.

After the last statement of a function executes, control passes to the ____

a)

calling function

b)

beginning of this function

c)

main function

d)

function whose code immediately follows this function's code

30.

What is the output of C Program.?

int main()

{

int ary[2][2][3] = {

{{1,2,3},{4,5,6}},

{{7,8,9},{10,11,12}}

};

printf("%d",*(*(*(ary+1)+ 1)+2));

return 0;

}

a)

10

b)

11

c)

12

d)

Compilation error