WorksheetsMastering C Programming Concepts
Total questions: 55
Worksheet time: 28mins
What is a linked list and how is it implemented in C?
A linked list is implemented using only arrays in C.
A linked list is a static array of elements.
A linked list is a data structure made of nodes, each containing data and a pointer to the next node, implemented in C using structures and pointers.
A linked list is a type of tree structure.
Explain the difference between a stack and a queue.
Both stack and queue use LIFO.
A stack uses LIFO, while a queue uses FIFO.
A stack allows random access, while a queue does not.
A stack uses FIFO, while a queue uses LIFO.
What are the advantages of using structures in C?
Advantages of using structures in C include better data organization, improved code readability, support for complex data types, and enhanced maintainability.
Structures are not compatible with functions in C.
Structures can only hold primitive data types.
Using structures increases memory usage without benefits.
How do you dynamically allocate memory in C?
Use 'new(size)' for dynamic allocation
Use 'alloc(size)' to reserve memory
Use 'malloc(size)', 'calloc(num, size)', or 'realloc(ptr, new_size)' to dynamically allocate memory in C.
Use 'free(ptr)' to allocate memory
What is a pointer and how is it different from a regular variable?
A pointer is a type of function that executes code.
A pointer is a special variable that cannot be changed once defined.
A pointer is a variable that stores a memory address, while a regular variable holds actual data values.
A pointer is a variable that can only store integer values.
Describe the process of passing an array to a function in C.
Declare the function with a parameter of type 'data_type *array_name' and pass the array by using its name.
Declare the function without any parameters and access the array globally.
Use a pointer to the first element of the array and pass it as a string.
Declare the function with a parameter of type 'data_type array_name[]' and pass the array by value.
What is recursion and how does it work in C?
Recursion is a technique that prevents functions from calling themselves in C.
Recursion is a method where a function calls itself in C, used to solve problems by breaking them into smaller subproblems.
Recursion is a method where a function runs in a loop in C.
Recursion is a way to optimize memory usage in C by avoiding function calls.
How do you prevent memory leaks in a C program?
Ignore memory allocation entirely.
Always free allocated memory and avoid losing references to it.
Always allocate memory without freeing it.
Use global variables for all data storage.
What is the purpose of the 'sizeof' operator in C?
The 'sizeof' operator converts data types to their string representations.
The 'sizeof' operator returns the size in bytes of a data type or variable.
The 'sizeof' operator is used to declare variables in C.
The 'sizeof' operator calculates the total memory usage of a program.
Explain the concept of function overloading in C.
Function overloading requires the functions to have the same number of parameters only.
Function overloading allows functions to have different names based on their return types.
Function overloading is a feature exclusive to C++ and not available in C.
Function overloading in C enables multiple functions with the same name to coexist, distinguished by their parameter types or counts.
What are the different types of data structures available in C?
Hash tables and heaps
Primitive data structures (arrays, structures), linked lists, stacks, queues, trees, graphs
Dictionaries and sets
Matrices and tensors
How do you implement a binary tree in C?
struct Element { int item; struct Element* next; };
struct BinaryTree { int key; struct BinaryTree* sibling; };
struct Node { int data; struct Node* left; struct Node* right; };
struct Tree { int value; struct Tree* parent; };
What is the role of the 'return' statement in a function?
The 'return' statement is used to define a function's parameters.
The 'return' statement outputs a value from a function and ends its execution.
The 'return' statement pauses a function's execution without outputting a value.
The 'return' statement allows a function to call another function.
How can you use pointers to manipulate strings in C?
Modify strings by copying them to a new array without pointers.
Use character pointers to access and modify string characters via pointer arithmetic.
Access string characters using array indexing only.
Use integer pointers to manipulate string lengths directly.
What is the difference between call by value and call by reference?
Call by value passes a reference to the variable, while call by reference passes a copy of the variable.
Call by value and call by reference are the same and have no differences.
Call by value modifies the original variable, while call by reference does not.
Call by value passes a copy of the variable, while call by reference passes a reference to the variable.
What is the purpose of the C Standard Library?
To provide a standardized set of functions for common programming tasks.
To manage hardware resources efficiently.
To provide a graphical user interface.
To create a new programming language.
Name three commonly used C Standard Library functions.
strcpy
strlen
free
printf, scanf, malloc
How do you declare a function in C?
function_name(parameter_type1 parameter_name1) return_type;
function_name(parameter_type1, parameter_type2);
return_type function_name(parameter_type1 parameter_name1, parameter_type2 parameter_name2, ...);
return_type function_name(parameter_name1, parameter_name2);
What is the difference between a function declaration and a function definition?
A function declaration introduces a function's name and parameters; a function definition includes the declaration and the implementation code.
A function declaration and definition are the same; both are used to execute a function.
A function declaration is used to call a function; a function definition is used to create a variable.
A function declaration includes the implementation code; a function definition only introduces the function's name.
Explain the concept of function overloading in C.
Function overloading is a feature that enables functions to return different types in C.
Function overloading allows multiple functions with the same name in C.
Function overloading can be achieved by using default parameters in C.
Function overloading is not natively supported in C, but can be simulated using different function names or by using macros.
What is an array in C?
An array in C is a single element of any type.
An array in C is a collection of elements of the same type stored in contiguous memory locations.
An array in C is a function that returns multiple values.
An array in C is a collection of different types stored randomly.
How do you initialize an array in C?
int arr[3] = {1, 2};
int arr[] = {1, 2, 3};
int arr = {1, 2, 3};
int arr[3] = new int[3];
What are the different data types available in C?
int, float, double, char, array, structure, union, pointer
list
boolean
string
What is the size of an int data type in C on a typical system?
16 bytes
2 bytes
4 bytes
8 bytes
What is the role of a compiler in C programming?
To optimize C code for better performance.
To execute C code directly without translation.
To debug C code and find errors.
The role of a compiler in C programming is to translate C code into machine code.
How does an interpreter differ from a compiler?
An interpreter compiles the entire code at once, while a compiler runs it line by line during execution.
An interpreter executes code line by line at runtime, while a compiler translates the entire code into machine code before execution.
An interpreter translates code into machine code before execution, while a compiler executes it line by line.
An interpreter and a compiler both execute code simultaneously without any difference in their processes.
What are control structures in C?
loops and functions
Control structures in C include 'if', 'else', 'switch', 'for', 'while', and 'do-while'.
data types and structures
memory management techniques
Give an example of a conditional control structure in C.
for (int i = 0; i < n; i++) { /* code */ }
if (condition) { /* code to execute if condition is true */ } else { /* code to execute if condition is false */ }
while (condition) { /* code */ }
switch (condition) { /* code */ }
What is a loop in C?
A loop in C is a control structure that enables repeated execution of a block of code.
A loop in C is a method for defining variables.
A loop in C is a function that returns a value.
A loop in C is a data type for storing multiple values.
Name the three types of loops available in C.
for, while, do while
step, cycle, traverse
foreach, until, repeat
repeat, iterate, loop
How do you create a for loop in C?
for(int i = 0; i < n; i++) // code to execute
for(int i = 0; i < n; i++) { // code to execute }
for(i = 0; i < n; i++) { // code to execute }
for(int i = 0; i < n; i++) { code to execute }
What is the purpose of the break statement in loops?
The break statement continues to the next loop iteration.
The break statement terminates the loop execution.
The break statement skips the current iteration of the loop.
The break statement pauses the loop execution.
Explain the use of the continue statement in loops.
The continue statement skips the current iteration of a loop and continues with the next iteration.
The continue statement terminates the loop immediately.
The continue statement is used to exit a loop completely.
The continue statement restarts the loop from the beginning.
What is the difference between while and do-while loops?
'Do-while' loops are used for infinite loops, while 'while' loops are not.
'While' loops can only execute once, while 'do-while' can execute multiple times.
The main difference is that 'while' checks the condition before execution, while 'do-while' checks it after.
Both loops check the condition before execution.
How can you iterate through an array using a loop?
Access each element directly by index without a loop.
Use a 'do-while' loop to iterate through the array.
Use a 'for' loop or 'forEach' method to iterate through the array.
Use a 'while' loop to iterate through the array.
Choose a right C Statement.
Loops or Repetition block executes a group of statements repeatedly.
Loop is usually executed as long as a condition is met.
Loops usually take advantage of Loop Counter
All the above.
What is the output of C Program.?
int main()
{
int a=5;
while(a >= 3);
{
printf("RABBIT\n");
break;
}
printf("GREEN");
return 0;
}
GREEN
RABBIT GREEN
RABBIT is printed infinite times
None of the above
What is the output of C Program.?
int main()
{
int a=25;
while(a <= 27)
{
printf("%d ", a);
a++;
}
return 0;
}
25 25 25
25 26 27
27 27 27
Compiler error
What is the output of C Program.?
int main()
{
int a=32;
do
{
printf("%d ", a);
a++;
}
while(a <= 30);
return 0;
}
32
33
30
No Output
What is the output of C Program.?
int main()
{
int a=32;
do
{
printf("%d ", a);
a++;
if(a > 35)
break;
}
while(1);
return 0;
}
No Output
32 33 34
32 33 34 35
Compiler error
Choose a correct C Statement.
a++ is (a=a+1) POST INCREMENT Operator
a-- is (a=a-1) POST DECREMENT Operator
--a is (a=a-1) PRE DECREMENT Operator
++a is (a=a+1) PRE INCREMENT Operator
All the above.
What is the output of C Program.?
int main()
{
int k;
for(k=1; k <= 5; k++);
{
printf("%d ", k);
}
return 0;
}
1 2 3 4 5
1 2 3 4
6
5
What is the output of C Program.?
int main()
{
int k;
for(;;)
{
printf("TESTING\n");
break;
}
return 0;
}
No Output
TESTING
Compiler error
None of the above
Loops in C Language are implemented using.?
While Block
For Block
Do While Block
All the above
What is the way to suddenly come out of or Quit any Loop in C Language.?
continue; statement
break; statement
leave; statement
quit; statement
Choose a correct C do while syntax.
dowhile(condition) { //statements }
do while(condition) { //statements }
do { //statements }while(condition)
do { //statements }while(condition);
What is the output of C Program.?
int main()
{
int a=5;
while(a=123)
{
printf("RABBIT\n");
break;
}
printf("GREEN");
return 0;
}
GREEN
RABBIT GREEN
RABBIT is printed unlimited number of times.
Compiler error.
In the following loop construct, which one is executed only once always.
for(exp1; exp2; exp3)
exp1
exp3
exp1 and exp3
exp1,exp2 and exp3
The continue statment cannot be used with
for
while
do while
switch
What will be the output of the following C code?
#include <stdio.h>
int main()
{
do{
printf("In while loop ");
}while (0);
printf("After loop\n");
}
In while loop
In while loop after loop
After loop
Infinite loop
What will be the output of the following C code?
#include <stdio.h>
int main()
{
int i = 0;
do {
i++;
printf("In while loop\n");
} while (i < 3);
}
In while loop
In while loop
In while loop
In while loop
In while loop
Depends on the compiler
Compile time error
Who is Father of C Language
Bjarne Stroustrup
James A. Gosling
Dennis Ritchie
Dr. E.F. Codd
C programs are converted into machine language with the help of
An Editor
A compiler
An operating system
None of these.
int main ()
{
int x = 24, y = 39, z = 45;
z = x + y;
y = z - y;
x = z - y;
printf ("%d %d %d", x, y, z);
}
24 39 63
39 24 63
24 39 45
39 24 45
