Here’s a list of 100 Important C language questions with their answers. I have categorized them into sections for better clarity.

Basic Concepts
(100 Important C language questions with their answers)
- What is C language?
Answer: C is a general-purpose, procedural programming language developed by Dennis Ritchie in the 1970s at Bell Labs. - What are keywords in C?
Answer: Keywords are reserved words in C, predefined by the language, such asint
,return
,if
,while
, etc. - What is the difference between
int
andfloat
?
Answer:int
is used for integer values.float
is used for decimal or floating-point values.
- What is a variable?
Answer: A variable is a storage location in memory with a name and a type to store data. - What is a constant in C?
Answer: A constant is a value that cannot be changed during the execution of a program.
Data Types and Operators
(100 Important C language questions with their answers)
- List the basic data types in C.
Answer:int
,float
,char
,double
. - What are derived data types in C?
Answer: Arrays, pointers, structures, and unions. - What is the purpose of the
sizeof()
operator?
Answer: It returns the size (in bytes) of a data type or variable. - What is typecasting?
Answer: Typecasting is converting a variable from one data type to another. - What is the difference between
=
and==
?
Answer:
=
is the assignment operator.==
is the equality operator for comparison.
Control Structures
(100 Important C language questions with their answers)
- What is an
if-else
statement?
Answer: It is a conditional statement that executes a block of code if the condition is true, and another block if it is false. - What is a
switch
statement?
Answer: A multi-way decision-making statement to execute one block of code among many options. - What is the difference between
while
anddo-while
?
Answer:
while
: Executes the block if the condition is true.do-while
: Executes the block at least once, then checks the condition.
- What is the syntax of a
for
loop?
Answer:
for (initialization; condition; increment/decrement) {
// Code block
}
- What is a nested loop?
Answer: A loop inside another loop.
Functions
(100 Important C language questions with their answers)
- What is a function in C?
Answer: A block of code that performs a specific task and can be reused. - What is the difference between
call by value
andcall by reference
?
Answer:
Call by value
: Copies the value of the argument.Call by reference
: Passes the address of the argument.
- What is the return type of
main()
in C?
Answer:int
. - What is a recursive function?
Answer: A function that calls itself. - How do you declare a function in C?
Answer:
return_type function_name(parameters);
Pointers
(100 Important C language questions with their answers)
- What is a pointer?
Answer: A pointer is a variable that stores the address of another variable. - How do you declare a pointer?
Answer:int *ptr;
- What is the
NULL
pointer?
Answer: A pointer that does not point to any memory location. - What is pointer arithmetic?
Answer: Operations like addition or subtraction performed on pointers. - What is a
void
pointer?
Answer: A pointer that can hold the address of any data type.
Arrays and Strings
(100 Important C language questions with their answers)
- What is an array in C?
Answer: A collection of elements of the same data type stored in contiguous memory locations. - How do you declare an array?
Answer:int arr[10];
- What is a multidimensional array?
Answer: An array with more than one dimension, such as a matrix. - How do you declare a string in C?
Answer:char str[20];
- What is the
strlen()
function?
Answer: It returns the length of a string.
Structures and Unions
(100 Important C language questions with their answers)
- What is a structure in C?
Answer: A user-defined data type to group different types of variables. - How do you declare a structure?
Answer:
struct struct_name {
int x;
char y;
};
- What is the difference between structure and union?
Answer:
- Structure: Allocates memory for all members.
- Union: Allocates shared memory for all members.
- What is the syntax for accessing structure members?
Answer:
structure_variable.member_name;
- How do you define a union?
Answer:
union union_name {
int x;
char y;
};
Advanced Topics
(100 Important C language questions with their answers)
- What is dynamic memory allocation?
Answer: Allocating memory at runtime using functions likemalloc()
,calloc()
,realloc()
, andfree()
. - What is a file in C?
Answer: A storage medium for saving data. - How do you open a file in C?
Answer:
FILE *fp = fopen("filename.txt", "mode");
- What is a preprocessor directive?
Answer: Instructions processed before compilation, starting with#
, like#include
. - What is a macro?
Answer: A preprocessor directive for defining constants or expressions using#define
.
Common Errors and Debugging
(100 Important C language questions with their answers)
- What is a syntax error?
Answer: An error in the code structure or grammar. - What is a segmentation fault?
Answer: An error caused by accessing memory not allocated to the program. - What is an infinite loop?
Answer: A loop that never terminates due to incorrect conditions. - What is the difference between a compiler and an interpreter?
Answer:
- Compiler: Converts entire code into machine code at once.
- Interpreter: Executes code line by line.
- What is debugging?
Answer: The process of identifying and fixing errors in a program.
Dynamic Memory Allocation
(100 Important C language questions with their answers)
- What is the
malloc()
function?
Answer:malloc()
allocates memory dynamically and returns a pointer to the allocated memory. Syntax:
ptr = (type*)malloc(size);
- What is the difference between
malloc()
andcalloc()
?
Answer:
malloc()
: Allocates a single block of memory.calloc()
: Allocates multiple blocks of memory and initializes them to zero.
- What does
free()
do?
Answer:free()
deallocates previously allocated memory. - What is
realloc()
used for?
Answer:realloc()
resizes the memory block allocated bymalloc()
orcalloc()
. - Why is dynamic memory allocation important?
Answer: It allows efficient use of memory by allocating memory as needed during program execution.
Files in C
(100 Important C language questions with their answers)
- What are the different modes to open a file?
Answer:
"r"
: Read"w"
: Write"a"
: Append"r+"
: Read and write
- How do you close a file?
Answer:
fclose(file_pointer);
- What is the purpose of
fscanf()
andfprintf()
?
Answer:
fscanf()
: Reads data from a file.fprintf()
: Writes data to a file.
- What is the difference between
fgetc()
andfgets()
?
Answer:
fgetc()
: Reads a single character from a file.fgets()
: Reads a string from a file.
- What is the use of
feof()
?
Answer: Checks if the end of the file has been reached.
Storage Classes
(100 Important C language questions with their answers)
- What are storage classes in C?
Answer: Storage classes define the scope, visibility, and lifetime of variables. - List the types of storage classes in C.
Answer:
auto
register
static
extern
- What is the difference between
auto
andregister
?
Answer:
auto
: Default storage class for local variables.register
: Suggests storing the variable in a CPU register for faster access.
- What is the purpose of the
static
keyword?
Answer: Thestatic
keyword retains a variable’s value between function calls. - What is the
extern
keyword?
Answer: Declares a global variable or function in another file.
Preprocessor Directives
(100 Important C language questions with their answers)
- What is the use of
#include
?
Answer: Includes the contents of a file (usually header files) in the program. - What does
#define
do?
Answer: Defines a macro or constant. - What is the purpose of
#undef
?
Answer: Undefines a macro. - What is a conditional compilation?
Answer: Compilation based on conditions using directives like#ifdef
,#ifndef
, etc. - What is the difference between
#ifdef
and#ifndef
?
Answer:
#ifdef
: Compiles the code if the macro is defined.#ifndef
: Compiles the code if the macro is not defined.
Functions
(100 Important C language questions with their answers)
- What is the default return type of a function in C?
Answer:int
. - Can a function return multiple values in C?
Answer: No, but you can use pointers or structures to achieve this. - What is the scope of a local variable?
Answer: Limited to the block or function where it is declared. - What is a global variable?
Answer: A variable declared outside all functions, accessible throughout the program. - What is function overloading?
Answer: C does not support function overloading; it’s a feature of C++ or other languages.
Bitwise Operators
(100 Important C language questions with their answers)
- What is the purpose of the
&
operator?
Answer: Bitwise AND. - What is the purpose of the
|
operator?
Answer: Bitwise OR. - What is the purpose of the
^
operator?
Answer: Bitwise XOR. - What is the purpose of the
~
operator?
Answer: Bitwise NOT. - What is a bitwise shift operator?
Answer:
<<
: Left shift.>>
: Right shift.
Error Handling
(100 Important C language questions with their answers)
- What is an error in C?
Answer: A mistake in the program that prevents it from executing correctly. - What are the types of errors in C?
Answer:
- Syntax errors
- Runtime errors
- Logical errors
- What is the purpose of
perror()
?
Answer: Displays a descriptive error message. - What is the
errno
variable?
Answer: A global variable used to indicate error codes. - How do you handle errors in C?
Answer: Using error-checking mechanisms likeif
conditions anderrno
.
Miscellaneous (100 Important C language questions with their answers)
- What is a typedef in C?
Answer: Used to create a new name for an existing type. - What is the purpose of the
const
keyword?
Answer: Declares variables that cannot be modified. - What is the difference between
break
andcontinue
?
Answer:
break
: Exits a loop or switch.continue
: Skips the current iteration of a loop.
- What is the purpose of
goto
?
Answer: Transfers control to a labeled statement. - What is a command-line argument?
Answer: Arguments passed to the program at the time of execution.
Programming Questions
(100 Important C language questions with their answers)
- Write a program to check if a number is even or odd.
#include <stdio.h> int main() { int num; printf("Enter a number: "); scanf("%d", &num); if (num % 2 == 0) printf("Even\n"); else printf("Odd\n"); return 0; }
- Write a program to calculate the sum of digits of a number.
#include <stdio.h> int main() { int num, sum = 0, digit; printf("Enter a number: "); scanf("%d", &num); while (num > 0) { digit = num % 10; sum += digit; num /= 10; } printf("Sum of digits: %d\n", sum); return 0; }
- Write a program to reverse a string.
#include <stdio.h> #include <string.h> int main() { char str[100], temp; int i, len; printf("Enter a string: "); gets(str); len = strlen(str); for (i = 0; i < len / 2; i++) { temp = str[i]; str[i] = str[len - i - 1]; str[len - i - 1] = temp; } printf("Reversed string: %s\n", str); return 0; }
Key Concepts
(100 Important C language questions with their answers)
- What is the difference between
char
andstring
?
Answer:
char
: Stores a single character.string
: Stores a sequence of characters (array ofchar
).
- What is a dangling pointer?
Answer: A pointer pointing to memory that has already been freed. - What is the difference between
exit()
andreturn
?
Answer:
exit()
: Terminates the program immediately.return
: Exits a function and returns a value.
- What is the stack in C?
Answer: A memory segment for local variables and function calls. - What is a heap in C?
Answer: A memory segment for dynamic memory allocation.
- What is the
How to build a website and make money