NEW
Font size
WorksheetsMastering C Programming Concepts
Total questions: 44
Worksheet time: 22mins
1. Which of the following is a valid declaration of an integer variable in C? A) int 1x; B) int x1; C) int x 1; D) int x-1;
int x1_
int x.1
int 1_x
B) int x1;
2. What is the output of the following code? int a = 5, b = 10; printf("%d", a + b); A) 15 B) 510 C) 5 D) 10;
A) 15
B) 510
C) 5
D) 10
3. Which operator is used to access the value at a pointer's address? A) & B) * C) -> D) ;
A) &
C) ->
B) *
D) ;
4. What will be the output of the following code? int x = 10; if (x > 5) { printf("Greater"); } else { printf("Smaller"); } A) Greater B) Smaller C) Error D) None;
Undefined
A) Greater
Lesser
Equal
5. Which of the following loops will always execute at least once? A) for B) while C) do-while D) None of the above;
C) do-while
D) until
B) repeat-until
A) foreach
6. How do you declare a two-dimensional array in C? A) int arr[5][5]; B) int arr(5,5); C) int arr{5,5}; D) int arr<5,5>;
int arr<5][5>;
int arr[5,5];
A) int arr[5][5];
int arr{5;5};
7. What is the correct way to define a function in C? A) void functionName(); B) functionName void(); C) void functionName[]; D) functionName[] void;
A) void functionName();
void functionName()[]
functionName() void;
void[] functionName();
8. Which of the following is a valid pointer declaration? A) int *ptr; B) int ptr*; C) *int ptr; D) ptr int*;
*ptr int;
int ptr*;
ptr *int;
A) int *ptr;
9. What does the malloc function do in C? A) Allocates memory on the stack B) Allocates memory on the heap C) Frees allocated memory D) None of the above;
Deallocates memory from the heap
Allocates memory in the cache
B) Allocates memory on the heap
Reserves memory for global variables
10. Which of the following is NOT a valid storage class in C? A) auto B) register C) static D) dynamic;
G) global
D) dynamic
F) external
E) virtual
11. What is the purpose of the #define preprocessor directive? A) To define a constant B) To include a file C) To create a function D) To declare a variable;
G) To handle exceptions
A) To define a constant
E) To execute a loop
F) To manage memory allocation
12. How can you pass an array to a function in C? A) By value B) By reference C) Both A and B D) None of the above;
By index
By pointer
By size
C) Both A and B
13. What will be the output of the following code? char str[] = "Hello"; printf("%c", str[1]); A) H B) e C) l D) o;
H
l
o
B
14. Which of the following statements is true about unions in C? A) They can hold multiple values at once. B) They can hold only one value at a time. C) They are faster than structures. D) None of the above;
They require more memory than structures.
They can be initialized with multiple values.
B) They can hold only one value at a time.
They can store different data types.
15. What is the correct syntax for opening a file in C? A) fopen(file, mode); B) open(file, mode); C) file_open(file, mode); D) None of the above;
get_file(file, mode);
A) fopen(file, mode);
file_access(file, mode);
read_file(file, mode);
16. Which of the following is a valid command-line argument in C? A) int main(int argc, char *argv[]) B) int main(char *argv[], int argc) C) int main() D) None of the above;
int main(char argc)
int main(int argv[], char argc)
int main(int argc)
A) int main(int argc, char *argv[])
17. What is the output of the following code? int x = 5; printf("%d", ++x); A) 5 B) 6 C) 7 D) Error;
A) 4
D) Compilation Error
B) 6
C) 8
18. Which of the following is a feature of recursion? A) It must have a base case. B) It cannot call itself. C) It is always faster than iteration. D) None of the above;
It can only call itself once.
It requires multiple base cases.
A) It must have a base case.
It is less efficient than loops.
19. What is the purpose of the free function in C? A) To allocate memory B) To deallocate memory C) To initialize memory D) To check memory usage;
C) To clear memory
A) To reserve memory
B) To deallocate memory
D) To monitor memory usage
20. Which of the following is true about strings in C? A) They are arrays of characters. B) They are null-terminated. C) Both A and B D) None of the above;
C
They are immutable.
They are fixed-length arrays.
They can contain integers.
21. What is the correct way to declare a constant in C? A) const int x = 10; B) int const x = 10; C) #define x 10; D) All of the above;
C) #define x 10;
A) const int x = 10;
D) All of the above;
B) int const x = 10;
22. Which of the following is a valid way to define a structure in C? A) struct { int x; }; B) struct point { int x; int y; }; C) struct point { int x, y; }; D) Both B and C;
A) struct { int x; };
B) struct point { int x; int y; };
D) Both B and C;
C) struct point { int x, y; };
23. What will be the output of the following code? int arr[] = {1, 2, 3}; printf("%d", arr[2]); A) 1 B) 2 C) 3 D) Error;
A) 1
B) 2
C) 3
D) Error
24. What is the output of the following code? int a = 10; int b = 20; printf("%d", a * b); A) 200 B) 30 C) 10 D) 20;
A) 200
B) 30
C) 10
D) 20
25. Which of the following is a valid way to declare a pointer to a function in C? A) int (*ptr)(); B) int ptr(); C) int *ptr(); D) None of the above;
A) int (*ptr)();
B) int ptr();
D) None of the above;
C) int *ptr();
26. What is the correct way to initialize a pointer in C? A) int *ptr = NULL; B) int ptr = *NULL; C) int *ptr = 0; D) Both A and C;
A) int *ptr = NULL;
B) int ptr = *NULL;
D) Both A and C;
C) int *ptr = 0;
27. Which of the following is the correct syntax for a for loop in C? A) for (int i = 0; i < 10; i++) B) for int i = 0; i < 10; i++ C) for (i = 0; i < 10; i++) D) for (int i; i < 10; i++);
A) for (int i = 0; i < 10; i++)
B) for int i = 0; i < 10; i++
C) for (i = 0; i < 10; i++)
D) for (int i; i < 10; i++);
28. What is the output of the following code? int x = 3; int y = 4; printf("%d", x + y * 2); A) 11 B) 14 C) 10 D) 7;
C) 10
A) 11
B) 14
D) 7
29. Which of the following statements is true about the sizeof operator in C? A) It returns the size of a variable in bytes. B) It can be used with any data type. C) Both A and B D) None of the above;
D) None of the above
B) It can be used with any data type.
C) Both A and B
A) It returns the size of a variable in bytes.
30. Which of the following is a correct way to declare a constant in C? A) const int x = 10; B) int const x = 10; C) Both A and B D) None of the above;
A) const int x = 10;
B) int const x = 10;
C) Both A and B
D) None of the above
31. What is the purpose of the 'return' statement in a function? A) To exit the function B) To return a value to the caller C) Both A and B D) None of the above;
B) To return a value to the caller
A) To exit the function
D) None of the above
C) Both A and B
32. Which of the following is a valid way to define a macro in C? A) #define PI 3.14 B) #define PI(x) (3.14 * (x)) C) Both A and B D) None of the above;
C) Both A and B
B) #define PI(x) (3.14 * (x))
A) #define PI 3.14
D) None of the above
25. Which of the following is the correct syntax for declaring a structure in C? A) struct { int x; }; B) struct myStruct { int x; }; C) Both A and B D) None of the above;
D) None of the above
C) Both A and B
B) struct myStruct { int x; };
A) struct { int x; };
15. What will be the output of the following code? int a = 2; int b = 3; printf("%d", a + b * 3); A) 11 B) 9 C) 5 D) 6;
D) 6
C) 5
B) 9
A) 11
22. Which of the following is a valid way to declare a function pointer in C? A) int (*ptr)(); B) int ptr*(); C) *int ptr(); D) ptr int*();
D) ptr int*();
A) int (*ptr)();
B) int ptr*();
C) *int ptr();
30. Which of the following is the correct way to declare a function that takes two integers and returns their sum? A) int sum(int a, int b); B) void sum(int a, int b); C) int sum(a, b); D) int sum(int, int);
A) int sum(int a, int b);
D) int sum(int, int);
B) void sum(int a, int b);
C) int sum(a, b);
24. What is the output of the following code? int a = 2, b = 3; printf("%d", a * b + b); A) 9 B) 8 C) 6 D) 5;
A) 9
B) 8
C) 6
D) 5
25. Which of the following statements is true about arrays in C? A) They can hold different data types. B) They are fixed in size once declared. C) They can be resized dynamically. D) None of the above;
A) They can hold different data types.
C) They can be resized dynamically.
B) They are fixed in size once declared.
D) None of the above
11. Which of the following is a valid way to declare a structure in C? A) struct { int x; }; B) struct myStruct { int x; }; C) Both A and B D) None of the above;
B) struct myStruct { int x; };
C) Both A and B
D) None of the above
A) struct { int x; };
20. What is the purpose of the 'sizeof' operator in C? A) To determine the size of a variable B) To allocate memory C) To deallocate memory D) To initialize a variable;
A) To determine the size of a variable
B) To allocate memory
C) To deallocate memory
D) To initialize a variable
27. Which of the following statements is true about pointers in C? A) Pointers can be incremented. B) Pointers can only point to integers. C) Pointers cannot be null. D) None of the above;
B) Pointers can only point to integers.
A) Pointers can be incremented.
D) None of the above
C) Pointers cannot be null.
30. What will be the output of the following code? int x = 4; int y = 5; printf("%d", x * y + y); A) 25 B) 20 C) 24 D) 30;
A) 25
B) 20
C) 24
D) 30
31. Which of the following is a valid way to define a function in C? A) void myFunction() {} B) function myFunction() {} C) myFunction() void {} D) None of the above;
D) None of the above
C) myFunction() void {}
B) function myFunction() {}
A) void myFunction() {}
32. What is the output of the following code? int a = 1, b = 2; printf("%d", a == b); A) 1 B) 0 C) Error D) None of the above;
B) 0
A) 1
D) None of the above
C) Error
