WorksheetsC Language Fundamentals Assessment
Total questions: 20
Worksheet time: 10mins
What is the primary purpose of algorithms in programming?
Algorithms are used to create user interfaces.
Algorithms help in designing hardware components.
The main role of algorithms is to store data efficiently.
The primary purpose of algorithms in programming is to provide a systematic method for solving problems.
Define a data type in C. Give examples.
Common data types in C: string, list, map, enum.
Types in C include: byte, decimal, object, pointer.
Examples of data types in C: int, float, char, struct.
Examples of data types in C: double, boolean, array, union.
What is the difference between an integer and a float in C?
An integer represents whole numbers; a float represents numbers with decimal points.
An integer can be a decimal; a float cannot be whole.
An integer is a floating-point number; a float is not.
An integer is used for text; a float is used for numbers.
Explain the use of operators in C programming.
Operators in C programming are symbols that perform operations on variables and values, categorized into arithmetic, relational, logical, bitwise, assignment, and increment/decrement operators.
Operators in C programming do not include bitwise or increment/decrement types.
Operators in C programming are limited to comparison and logical checks.
Operators in C programming are only used for arithmetic calculations.
What is the output of the following code: printf("%d", 5 + 3);?
10
9
6
8
How do you declare a variable in C?
char variableName;
double variableName;
int variableName;
float variableName;
What is the significance of the 'main' function in a C program?
The 'main' function handles memory allocation.
The 'main' function is used for variable declaration.
The 'main' function is the entry point of a C program.
The 'main' function is for defining global variables.
Describe the difference between '==' and '=' in C.
In C, '=' checks for equality, and '==' is used to declare variables.
In C, '=' is used for logical operations, while '==' is for variable assignment.
In C, '=' assigns a value to a variable, and '==' compares two values for equality.
In C, '=' compares two values, and '==' assigns a value to a variable.
What are logical operators in C? Provide examples.
1. XOR: (a == 5 ^ a == 10)
2. NAND: !(a > 5 && a < 10)
3. NOR: !(a < 5 || a > 10)
Examples: 1. AND: (a > 5 && a < 10) 2. OR: (a < 5 || a > 10) 3. NOT: !(a == 5)
What is a pointer in C and how is it used?
A pointer in C is a type of function that executes code directly.
A pointer in C is a variable that holds the address of another variable, enabling direct memory access and manipulation.
A pointer in C is a special variable that stores string values only.
A pointer in C is an object that represents a data structure without memory access.
Explain the concept of arrays in C.
An array in C is a dynamic structure that grows in size during runtime.
An array in C is a collection of different types of elements stored randomly.
An array in C is a collection of elements of the same type, stored in contiguous memory, accessed via indices.
An array in C is a single variable that can hold multiple data types.
What is the purpose of the 'sizeof' operator?
The purpose of the 'sizeof' operator is to return the size of a data type or object in bytes.
The 'sizeof' operator is used to allocate memory for variables.
The 'sizeof' operator determines the maximum value of a data type.
The 'sizeof' operator calculates the total number of elements in an array.
How do you create a function in C?
function_name(parameter_type) => { // body }
return_type { function_name(parameter_type) }
return_type function_name(parameter_type parameter_name) { // function body }
function_name(parameter_name) { // body }
What is the difference between a local and a global variable?
Local variables exist for the entire program, while global variables are temporary.
Local variables can be accessed globally, while global variables are limited to a function.
Local variables are always public, whereas global variables are private to a block.
Local variables are scoped to a function or block, while global variables are accessible throughout the entire program.
What are control structures in C? Give examples.
1. else statement: 'else { // code }'
Examples of control structures in C are: 1. if statement: 'if (condition) { // code }' 2. switch statement: 'switch (variable) { case value: // code; break; }' 3. for loop: 'for (initialization; condition; increment) { // code }' 4. while loop: 'while (condition) { // code }' 5. do-while loop: 'do { // code } while (condition);'
2. case statement: 'case (value): // code;'
3. foreach loop: 'foreach (item in collection) { // code }'
What is recursion in algorithms? Provide a simple example.
A simple example of recursion is the Fibonacci sequence, defined as F(n) = F(n-1) + F(n-2) with F(0) = 0.
Recursion is a method where a function calls itself to solve a problem, like reversing a string.
An example of recursion is the sum of an array, calculated as sum(arr) = arr[0] + sum(arr[1:]).
A simple example of recursion is the calculation of the factorial of a number n, defined as n! = n * (n-1)! with the base case 0! = 1.
How do you handle errors in C programming?
Ignore errors and continue execution, assuming success.
Always terminate the program on any error encountered.
Handle errors by checking return values, using errno, implementing error handling functions, and using setjmp/longjmp for non-local jumps.
Use print statements to debug without handling errors.
What is the role of header files in C?
Header files provide function declarations, macros, and type definitions to facilitate code organization and reuse.
Header files are primarily for managing user input and output.
Header files are used to store executable binaries for programs.
Header files contain only comments and documentation for code.
Explain the concept of dynamic memory allocation in C.
Dynamic memory allocation in C is the process of freeing memory before program execution.
Dynamic memory allocation in C is the process of allocating memory during program execution using functions like malloc and free.
Dynamic memory allocation in C is done at compile time using static arrays.
Dynamic memory allocation in C uses fixed-size buffers for memory management.
What is the difference between 'break' and 'continue' statements?
'break' skips to the next iteration, while 'continue' exits the loop.
'break' pauses the loop, while 'continue' restarts it from the beginning.
'break' exits the loop, while 'continue' skips to the next iteration.
'break' terminates the program, while 'continue' ends the function.
