Miscellaneous Questions - CSU1128 - CSE 2026 - Shoolini University

Collection of Miscellaneous Questions to test your knowledge.

Test your knowledge under the course Logic Building with Computer Programming (CSU1128) under the guidance by Dr. Pankaj Vaidya.

What is the main function in a C program, and what is its purpose?

Answer: The main function in a C program is the starting point of execution. It is the entry point of the program and must return an integer value. The purpose of the main function is to define the flow of execution for the program.

How do you declare a variable in C, and what are the basic data types?

Answer: In C, variables are declared with a specific data type, such as int, float, or char. For example, to declare an integer variable named "x", you would use the syntax "int x;". The basic data types in C include int (integer), float (floating-point number), double (double precision floating-point number), char (character), and _Bool (boolean).

What is the difference between a global variable and a local variable in C?

A global variable in C is a variable that is accessible from any function or block in the program. A local variable, on the other hand, is only accessible from within the function or block in which it is defined.

How do you use conditional statements (e.g. if, else) in C?

Conditional statements in C allow you to execute different code based on a certain condition. The if statement is used to execute a block of code if a condition is true. The else statement is used to execute a block of code if the condition in the if statement is false. The syntax for an if-else statement is: if (condition) { // code to execute if condition is true } else { // code to execute if condition is false }

Can you explain the concept of pointers in C and how they are used?

Pointers in C are variables that store the memory address of another variable. They are used to pass variables by reference, rather than by value. To declare a pointer, the syntax is variable_type *pointer_name;. The unary operator * is used to access the value stored at the memory address pointed to by the pointer.

How do you use arrays in C, and what are the different types of arrays?

Arrays in C are a collection of variables of the same data type. They are declared with a specific size and can be accessed using an index. The syntax for declaring an array is variable_type array_name[size];.

Can you explain the concept of a structure in C, and how it is different from an array?

A structure in C is a user-defined data type that can hold multiple variables of different data types. It is similar to an object in object-oriented programming languages. The syntax for declaring a structure is struct structure_name { variable_type variable_name; };

How do you perform input/output operations in C, and what are the main functions used for this?

Input/output operations in C are performed using a set of functions from the standard library, such as scanf() and printf(). scanf() is used for reading input from the user, and printf() is used for displaying output to the user.

Explain the concept of recursion in C, and give an example of a recursive function?

Recursion in C is a programming technique where a function calls itself. A function that uses recursion is called a recursive function. An example of a recursive function in C is a function that calculates the factorial of a number.

How do you use dynamic memory allocation in C, and what are the main functions used for this?

Dynamic memory allocation in C is the process of allocating memory to a program while it is running. The main functions used for this are malloc() and calloc(), which are used to allocate memory dynamically, and free() which is used to deallocate memory when it is no longer needed.

What is the difference between a global variable and a local variable?

A global variable is a variable that is declared outside of any function and is accessible to all functions in the program. A local variable, on the other hand, is a variable that is declared inside a function and is only accessible within that function.

What is the purpose of the "main" function in a C program?

The "main" function is the entry point of a C program. It is the function where the program begins executing and is usually where the majority of the program logic is contained.

How do you use the "if" statement to control the flow of a program?

The "if" statement is used to control the flow of a program based on a specific condition. The syntax for an "if" statement in C is as follows:


if (condition) {
// code to be executed if condition is true
}

How do you declare and use an array in a C program?

To declare an array in C, you need to specify the type of data the array will hold and the number of elements it will contain. For example:

int array[10];
To access an element of the array, you can use the index operator ([]). For example:
array[0] = 10;

What is the difference between the "for" loop and the "while" loop?

The "for" loop is used to execute a block of code a specific number of times. The syntax for a "for" loop in C is as follows:


for (initialization; condition; update) {
// code to be executed
}
The "while" loop, on the other hand, is used to execute a block of code repeatedly as long as a specific condition is true. The syntax for a "while" loop in C is as follows:

while (condition) {
// code to be executed
}

What is the difference between a struct and a union in C?

A struct in C is a composite data type that allows you to store a group of related variables under a single name. A union, on the other hand, is a composite data type that allows you to store different variables in the same memory location. This means that when you use a union, only one of the variables in the union can be stored in memory at any given time.

What is the difference between a struct and a union in C?

A struct in C is a composite data type that allows you to store a group of related variables under a single name. A union, on the other hand, is a composite data type that allows you to store different variables in the same memory location. This means that when you use a union, only one of the variables in the union can be stored in memory at any given time.

How do you use pointers in C?

Pointers in C are variables that store the memory address of another variable. You can use pointers to access and modify the value of a variable indirectly, rather than directly accessing the variable itself. To declare a pointer in C, you use the "*" operator. For example:

int *pointer;

What is the purpose of the "const" keyword in C?

The "const" keyword in C is used to declare a variable as constant, which means that the value of the variable cannot be modified after it is initialized. This is useful for ensuring that the value of a variable is not accidentally changed by other parts of the program.

How do you use the "switch" statement to control the flow of a program?

The "switch" statement in C is used to execute a block of code based on the value of a specific expression. The syntax for a "switch" statement in C is as follows:


switch (expression) {
case value1:
// code to be executed if expression == value1
break;
case value2:
// code to be executed if expression == value2
break;
...
default:
// code to be executed if expression does not match any of the cases
}

What is the difference between a static function and a non-static function in C?

A static function in C is a function that is only accessible within the file in which it is defined. This means that the function cannot be called from other files in the program. A non-static function, on the other hand, is a function that is accessible to all parts of the program.

What is the difference between an "automatic" variable and a "static" variable in C?

An "automatic" variable in C is a variable that is created on the stack when a function is called and is automatically destroyed when the function returns. A "static" variable, on the other hand, is a variable that is created in memory when the program starts and remains in memory until the program ends. This means that a static variable retains its value between function calls, whereas an automatic variable does not.

How do you use recursion to solve a problem in C?

Recursion is a programming technique in which a function calls itself to solve a problem. In C, you can use recursion to solve problems that can be divided into smaller subproblems that can be solved independently. To use recursion in C, you need to define a base case that the function can use to stop calling itself, and you need to make sure that the function calls itself with a modified version of the original problem each time it is called.

What is the purpose of the "typedef" keyword in C?

The "typedef" keyword in C is used to create an alias for a data type. This allows you to use the alias as if it were a new data type in your program. For example:

typedef unsigned int UINT;
You can then use the "UINT" type in your program like this:
UINT x;

How do you use the "goto" statement in C?

The "goto" statement in C is used to transfer control to a different part of a program. The syntax for a "goto" statement in C is as follows:


goto label;

...

label:
// code to be executed
Using the "goto" statement is generally considered to be bad programming practice, as it can make code harder to read and understand.

How do you use the "sizeof" operator in C?

The "sizeof" operator in C is used to determine the size of a data type or a variable in bytes. For example:

int x;
printf("%d\n", sizeof(x)); // prints "4"
You can also use the "sizeof" operator to determine the size of a data type like this:
printf("%d\n", sizeof(int)); // prints "4"

What is the difference between a "dynamic" and a "static" memory allocation in C?

In C, you can use "dynamic" memory allocation to allocate memory for a variable at runtime, using functions such as "malloc" and "calloc". This means that the amount of memory allocated for the variable is not fixed at compile-time, but can be changed at runtime based on the needs of the program. "Static" memory allocation, on the other hand, is the process of allocating memory for a variable at compile-time, using the "static" keyword. This means that the amount of memory allocated for the variable is fixed at compile-time and cannot be changed at runtime.

How do you use the "fopen" and "fclose" functions to read and write to a file in C?

The "fopen" function in C is used to open a file for reading or writing. The syntax for "fopen" is as follows:

FILE *fopen(const char *filename, const char *mode);
The "filename" argument is the name of the file you want to open, and the "mode" argument specifies whether you want to read from the file ("r"), write to the file ("w"), or append to the file ("a"). To close a file that has been opened with "fopen", you can use the "fclose" function like this:
int fclose(FILE *stream);
The "stream" argument is a pointer to the file stream you want to close.

What is the difference between a "deep copy" and a "shallow copy" in C?

A "deep copy" in C is a copy of an object that includes not just the values of the object's attributes, but also any dynamically-allocated memory associated with the object. A "shallow copy", on the other hand, is a copy of an object that includes only the values of the object's attributes, and does not include any dynamically-allocated memory associated with the object.

How do you use the "assert" function to test assumptions in a C program?

The "assert" function in C is used to test assumptions in a program. If the assumption being tested is false, the "assert" function will print an error message and terminate the program. The syntax for "assert" is as follows:

assert(expression);
If "expression" is true, the "assert" function does nothing. If "expression" is false, the "assert" function prints an error message and terminates the program.

What is the difference between a "blocking" and a "non-blocking" function in C?

A "blocking" function in C is a function that stops the program from executing until it finishes running. A "non-blocking" function, on the other hand, is a function that allows the program to continue running while the function is executing. Non-blocking functions are useful for performing tasks that may take a long time to complete, as they allow the program to continue running and perform other tasks while the function is running.

What is the difference between a "preprocessor" directive and a "compiler" directive in C?

In C, a "preprocessor" directive is a line of code that begins with a "#" symbol and is processed by the preprocessor before the program is compiled. Preprocessor directives are used to include header files, define macros, and perform other tasks that are not possible using regular C code. A "compiler" directive, on the other hand, is a line of code that is recognized by the compiler and is used to specify compiler options or to include compiler-specific code.