wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

CP midsem2 set3

Total questions: 31

Worksheet time: 32mins

Name
Class
Date
1-3.

(mandatory) Enter your details carefully :

1.

Enter your 11 digit enrollment number:

4 lines
2.

Enter your class (DC1/DC2/DC3):

4 lines
3.

Enter your full name in following format (firstname lastname) ex. Pooja Raval

4 lines
4.
Which of the following is true about functions in C?
a)
Functions cannot return values
b)
Functions cannot accept arguments
c)
Functions help in code reusability and modularity
d)
Functions cannot be called recursively
5.
What is the syntax for defining a function in C?
a)
return_type function_name(parameters) {}
b)
function_name(parameters) return_type {}
c)
parameters return_type function_name {}
d)
function_name {} parameters return_type
6.
What is the return type of a function that does not return any value in C?
a)
int
b)
void
c)
char
d)
float
7.
What is the keyword used to define a structure in C?
a)
struct
b)
structure
c)
str
d)
class
8.
Which of the following is true about structures in C?
a)
A structure can contain variables of different data types
b)

A structure can contain variables of int data types

c)

A structure can contain variables of float data types

d)

A structure can contain variables of char types

9.

Predict the output: #include <stdio.h>

struct Point{

int x; int y;

};

int main() {

struct Point p;

p.x = 5; p.y = 10;

printf("(%d, %d)", p.x, p.y);

return 0;

}

a)
(0, 0)
b)
(5, 10)
c)
(10, 5)
d)
Compiler error
10.
What does the '*' operator do when used with pointers in C?
a)
Declares a pointer variable
b)
Retrieves the address of a variable
c)
Retrieves the value stored at a memory address
d)
Performs bitwise AND operation
11.
Which of the following correctly declares a pointer variable in C?
a)
int *ptr;
b)
ptr int;
c)
ptr int;
d)
int ptr;
12.
What is the purpose of the fflush() function in C?
a)
It closes the file
b)
It flushes the output buffer
c)
It moves the file pointer to the beginning of the file
d)
It reads data from the file
13.
What is the purpose of the ftell() function in C?
a)
It reads data from a file
b)
It writes data to a file
c)
It returns the current position of the file pointer in a file
d)
It closes a file
14.

What is the output of the following code?

#include <stdio.h>

int main() {

FILE *fp = fopen("example.txt", "w");

fprintf(fp, "Hello, World!");

fseek(fp, 0, SEEK_SET);

char str[20];

fgets(str, 20, fp);

printf("%s", str);

fclose(fp);

return 0;}

a)
Compiler error
b)
Runtime error
c)
Hello, World!
d)
No output
15.
What is the purpose of the fputs() function in C?
a)
It writes a string to a file
b)
It reads a string from a file
c)
It moves the file pointer to a specific location in a file
d)
It flushes the output buffer
16.
What is the purpose of the fgets() function in C?
a)
It writes a string to a file
b)
It reads a string from a file
c)
It moves the file pointer to a specific location in a file
d)
It flushes the output buffer
17.
Predict the output: #include <stdio.h> int main() { int num = 5; int *ptr = &num; printf("%p", &ptr); return 0;}
a)
Address of the pointer variable
b)

value of the 'num' variable

c)

Value of the 'pointer' variable

d)
Compiler error
18.
What is the output of the following code? #include <stdio.h> int main() { int arr[] = {1, 2, 3, 4, 5}; int *ptr = arr; printf("%d", ptr[3]); return 0;}
a)
1
b)
2
c)
3
d)
4
19.
Which of the following statements about pointers is true?
a)
Pointers can only store memory addresses of integer variables
b)
Pointers cannot be dereferenced
c)
Pointers can be used to access elements of arrays
d)
d) Pointers cannot be reassigned to point to different memory locations
20.

Predict the output: #include <stdio.h> int main() { int num1 = 5, num2 = 10; int *ptr1 = &num1,

*ptr2 = &num2; *ptr1 = *ptr2; printf("%d", num1); return 0;}

a)
5
b)
10
c)
Address of the 'num1' variable
d)
Compiler error
21.

What is the output of the following code? #include <stdio.h>

struct Point {

int x; int y;

};

int main() {

struct Point p = {3, 4};

printf("%d", p.x + p.y);

return 0;}

a)
3
b)
4
c)
7
d)
Compiler error
22.
Which of the following statements is true about unions in C?
a)
A union can contain variables of different data types
b)
A union can only contain variables of the same data type
c)
Unions cannot be passed as arguments to functions
d)
Unions cannot be initialized at the time of declaration
23.
What is the purpose of using structures in C?
a)
To group related variables together
b)
To perform mathematical operations
c)
c) To define loops
d)
To allocate memory dynamically
24.
Predict the output: #include <stdio.h> union Value { int x; float y; }; int main() { union Value v; v.x = 10; v.y = 20.5; printf("%d %f", v.x, v.y); return 0; }
a)
10 20.5
b)
20 10.0
c)
Compiler error
d)
Runtime error
25.
Predict the output: #include <stdio.h> struct Point { int x; int y; }; int main() { struct Point p; p.x = 5; p.y = 10; printf("(%d, %d)", p.x, p.y); return 0;}
a)
(0, 0)
b)
(5, 10)
c)
(10, 5)
d)
Compiler error
26.
What does the '*' operator do when used with pointers in C?
a)
Declares a pointer variable
b)
Retrieves the address of a variable
c)
Retrieves the value stored at a memory address
d)
Performs bitwise AND operation
27.
Which of the following correctly declares a pointer variable in C?
a)
int *ptr;
b)
ptr int;
c)
ptr int;
d)
int ptr;
28.

Predict the output: #include <stdio.h>

int main() {

int x = 5;

int ptr = &x;

printf("%d", *ptr);

return 0;

}

a)
Address of the pointer variable
b)
Address of the 'x' variable
c)
Value of the 'x' variable
d)
Compiler error
29.
Which of the following libraries is used for file handling in C programming?
a)
stdlib.h
b)
stdio.h
c)
string.h
d)
math.h
30.
What does the expression *(ptr + 2) represent in C, where ptr is a pointer variable?
a)
Value stored at the memory location two positions after ptr
b)
Address stored at ptr incremented by 2
c)
Addition of 2 to the value pointed by ptr
d)
Multiplication of 2 with the value pointed by ptr
31.
Which of the following correctly declares a pointer to an array in C?
a)
int ptr[];
b)
ptr int[];
c)
int *ptr[];
d)
int (*ptr)[];
32.

Which of the following is the correct way to declare a function in C?

a)

int functionName;

b)

functionName int()

c)

int functionName()

d)

functionName() int

33.

Which of the following function declarations is correct?

a)

int add(int a, b)

b)

int add(int, int)

c)

int add(int a, int b)

d)

int add(a, b)