Skip to content

Commit c965d6e

Browse files
authored
Create functions.json
1 parent 1bef8eb commit c965d6e

1 file changed

Lines changed: 131 additions & 0 deletions

File tree

public/data/c/functions.json

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
{
2+
"id": "c-functions",
3+
"language": "c",
4+
"chapter": "functions",
5+
"title": "C Functions",
6+
"description": "Test your knowledge of C functions including function declaration, definition, calling, and recursion",
7+
"difficulty": "beginner",
8+
"estimatedTime": 15,
9+
"questions": [
10+
{
11+
"id": 1,
12+
"question": "What is a function in C?",
13+
"options": [
14+
"A variable that stores data",
15+
"A block of code that performs a specific task",
16+
"A header file",
17+
"A keyword"
18+
],
19+
"correctAnswer": 1,
20+
"explanation": "A function is a block of code designed to perform a specific task and can be reused multiple times."
21+
},
22+
{
23+
"id": 2,
24+
"question": "Which part of a function tells the compiler about the function name, return type, and parameters?",
25+
"options": [
26+
"Function call",
27+
"Function definition",
28+
"Function declaration",
29+
"Header file"
30+
],
31+
"correctAnswer": 2,
32+
"explanation": "Function declaration informs the compiler about the function’s name, return type, and parameters."
33+
},
34+
{
35+
"id": 3,
36+
"question": "Which of the following correctly declares a function that returns an integer?",
37+
"options": [
38+
"function add(int a, int b);",
39+
"int add(int a, int b);",
40+
"add(int a, int b);",
41+
"integer add(int a, int b);"
42+
],
43+
"correctAnswer": 1,
44+
"explanation": "In C, a function declaration must specify the return type followed by the function name and parameters."
45+
},
46+
{
47+
"id": 4,
48+
"question": "Where is the actual code of a function written?",
49+
"options": [
50+
"Function declaration",
51+
"Function prototype",
52+
"Function definition",
53+
"Function call"
54+
],
55+
"correctAnswer": 2,
56+
"explanation": "The function definition contains the actual body (code) of the function."
57+
},
58+
{
59+
"id": 5,
60+
"question": "What is a function call?",
61+
"options": [
62+
"Writing the function body",
63+
"Declaring a function",
64+
"Invoking a function to execute its code",
65+
"Including a header file"
66+
],
67+
"correctAnswer": 2,
68+
"explanation": "A function call is used to invoke a function and execute the statements defined inside it."
69+
},
70+
{
71+
"id": 6,
72+
"question": "Which keyword is used to return a value from a function?",
73+
"options": [
74+
"break",
75+
"exit",
76+
"return",
77+
"continue"
78+
],
79+
"correctAnswer": 2,
80+
"explanation": "The return keyword sends a value back to the calling function and ends function execution."
81+
},
82+
{
83+
"id": 7,
84+
"question": "What will happen if a function does not return any value?",
85+
"options": [
86+
"Program will crash",
87+
"Compiler error always occurs",
88+
"It should be declared with void return type",
89+
"It must return 0"
90+
],
91+
"correctAnswer": 2,
92+
"explanation": "Functions that do not return a value should be declared with the void return type."
93+
},
94+
{
95+
"id": 8,
96+
"question": "What is recursion?",
97+
"options": [
98+
"Calling one function from another",
99+
"Calling a function repeatedly using loops",
100+
"A function calling itself",
101+
"A function without parameters"
102+
],
103+
"correctAnswer": 2,
104+
"explanation": "Recursion is a process where a function calls itself to solve a problem in smaller parts."
105+
},
106+
{
107+
"id": 9,
108+
"question": "Which condition is necessary to stop a recursive function?",
109+
"options": [
110+
"Loop condition",
111+
"Break statement",
112+
"Base condition",
113+
"Return type"
114+
],
115+
"correctAnswer": 2,
116+
"explanation": "A base condition is required in recursion to stop further recursive calls and prevent infinite recursion."
117+
},
118+
{
119+
"id": 10,
120+
"question": "What happens if a recursive function has no base condition?",
121+
"options": [
122+
"Program executes normally",
123+
"Function executes only once",
124+
"Infinite recursion occurs",
125+
"Compiler automatically stops it"
126+
],
127+
"correctAnswer": 2,
128+
"explanation": "Without a base condition, a recursive function will keep calling itself, leading to infinite recursion and stack overflow."
129+
}
130+
]
131+
}

0 commit comments

Comments
 (0)