Basic C Programming Questions
1. What is C programming?
o Answer: C programming is a procedural and structured programming
language developed by Dennis Ritchie in 1972. It is widely used for
system programming and developing operating systems.
2. What are the basic data types in C?
o Answer: The basic data types in C are:
int: integer data type.
char: character data type.
float: floating-point data type.
double: double precision floating-point data type.
3. What is the purpose of #include in C?
o Answer: #include is a preprocessor directive used to include header
files in a C program. This is needed to use functions and other
definitions from libraries.
4. What is a function in C?
o Answer: A function in C is a block of code that performs a specific
task. It can take inputs, process them, and return an output.
5. What are the control structures in C?
o Answer: The control structures in C include:
Decision-making: if, if-else, switch
Looping: for, while, do-while
Jumping: break, continue, return
6. What is the difference between =, ==, and ===?
o Answer:
= is the assignment operator.
== is the comparison operator to check equality.
, === does not exist in C, but is used in languages like JavaScript
for strict equality.
7. What is the use of void in C?
o Answer: void is used to indicate that a function does not return a
value, or to specify that a pointer does not point to any specific data
type.
8. What is a pointer in C?
o Answer: A pointer is a variable that holds the memory address of
another variable.
9. What is the difference between a local and global variable?
o Answer:
A local variable is declared inside a function and can only be
accessed within that function.
A global variable is declared outside all functions and can be
accessed by any function in the program.
10.What is an array in C?
Answer: An array is a collection of variables of the same data type, stored
in contiguous memory locations.
Intermediate C Programming Questions
11.What is a function prototype in C?
Answer: A function prototype is a declaration of a function before its actual
definition, specifying the function’s return type and parameters.
12.What is recursion in C?
, Answer: Recursion is a process in which a function calls itself. It is used to
solve problems that can be broken down into smaller, similar problems.
13.Explain the use of break and continue in C.
Answer:
o break: Exits from the nearest loop or switch statement.
o continue: Skips the current iteration of the loop and proceeds with
the next iteration.
14.What is a structure in C?
Answer: A structure is a user-defined data type in C that groups different
types of data together, allowing you to store and manipulate multiple
variables of different data types.
15.Explain the difference between malloc() and calloc().
Answer:
o malloc(): Allocates a block of memory of a specified size and returns
a pointer to it.
o calloc(): Allocates memory for an array of elements, initializes all
elements to 0, and returns a pointer.
16.What is a union in C?
Answer: A union is similar to a structure, but it allows storing different data
types in the same memory location. Only one member can store a value at
any given time.
17.What is a linked list in C?
Answer: A linked list is a linear data structure where each element (node)
points to the next node in the sequence. It allows dynamic memory
allocation.
18.What is a dangling pointer?
Answer: A dangling pointer is a pointer that points to a memory location
that has been deallocated, causing undefined behavior if accessed.