Interview questions in C, Java and Python
C Programming
Interview Questions (30+ Questions)
Basic C Questions
- What is C language?
- C is a procedural, mid-level programming
language developed by Dennis Ritchie in 1972.
- What are the key features of C?
- Portability, efficiency, modularity, and low-level
memory access.
- What is a pointer in C?
- A pointer is a variable that stores the
memory address of another variable.
- What is the difference between malloc() and calloc()?
- malloc() allocates memory without
initialization, while calloc() initializes memory to zero.
- What is the use of static keyword in C?
- It retains the value of a variable
between function calls and limits scope to the file (for global
variables).
- Explain const keyword in C.
- It makes a variable read-only
(immutable).
- What is a dangling pointer?
- A pointer pointing to a deallocated
memory location.
- What is recursion? Give an example.
- A function calling itself (e.g.,
factorial calculation).
- Difference between ++i and i++?
- ++i is
pre-increment, i++ is post-increment.
- What is a header file in C?
- Contains function declarations and macros
(e.g., stdio.h).
Intermediate C
Questions
- What is a structure in C?
- A user-defined data type that groups
different data types.
- What is a union in C?
- Similar to a structure but shares memory
for all members.
- What is the difference between struct and union?
- Struct allocates separate memory for each
member; union shares memory.
- What is typedef in C?
- Used to create an alias for a data type.
- What is volatile keyword in C?
- Prevents compiler optimization for
variables that may change unexpectedly.
- What is a memory leak?
- When dynamically allocated memory is not
freed, causing wasted memory.
- What is #pragma in C?
- A compiler directive for special
instructions.
- Explain sizeof() operator.
- Returns the size (in bytes) of a variable
or data type.
- What is a function pointer?
- A pointer that points to a function
instead of a variable.
- What is strtok() in C?
- Used to split strings into tokens.
Advanced C
Questions
- What is the difference between memcpy() and memmove()?
- memmove() handles overlapping memory
regions; memcpy() does not.
- What is a far pointer?
- Used in segmented architectures to access
memory outside the current segment.
- What is a null pointer?
- A pointer that does not point to any
valid memory location (NULL).
- What is a void pointer?
- A generic pointer that can point to any
data type.
- What is the difference between #include <file.h> and #include
"file.h"?
- <file.h> searches in system
directories, "file.h" searches in local directories.
- What is a bit field in C?
- A data structure that stores data in
bits.
- What is restrict keyword in C?
- Indicates that a pointer is the only way
to access the memory it points to.
- What is setjmp() and longjmp()?
- Used for non-local jumps in C.
- What is a file descriptor in C?
- An integer representing an open file.
- What is errno in C?
- A global variable indicating error codes.
Java Programming
Interview Questions (40+ Questions)
Basic Java
Questions
- What is Java?
- An object-oriented, platform-independent
programming language.
- What is JVM?
- Java Virtual Machine executes Java
bytecode.
- Difference between JDK, JRE, and JVM?
- JDK (Development Kit), JRE (Runtime
Environment), JVM (Execution Engine).
- What is the main method in Java?
- Entry point of a Java program (public
static void main(String[] args)).
- What are Java access modifiers?
- public, private, protected, and
default (package-private).
- What is method overloading?
- Multiple methods with the same name but
different parameters.
- What is method overriding?
- Redefining a parent class method in a
child class.
- What is the final keyword in Java?
- Makes a variable constant, a method
non-overridable, or a class non-inheritable.
- What is a constructor?
- A special method called when an object is
created.
- What is the difference between == and .equals()?
- == checks
reference, .equals() checks content.
Intermediate Java
Questions
- What is the difference between String, StringBuilder,
and StringBuffer?
- String is
immutable, StringBuilder is mutable & not
thread-safe, StringBuffer is thread-safe.
- What is exception handling in Java?
- Using try-catch-finally blocks
to handle runtime errors.
- What are checked and unchecked exceptions?
- Checked (compile-time,
e.g., IOException), Unchecked (runtime, e.g., NullPointerException).
- What is multithreading in Java?
- Running multiple threads simultaneously.
- Difference between extends and implements?
- extends for
inheritance, implements for interfaces.
- What is a singleton class?
- A class that allows only one instance.
- What is the static keyword in Java?
- Belongs to the class rather than
instances.
- What is garbage collection in Java?
- Automatic memory management by JVM.
- What are Java collections?
- Frameworks
like List, Set, Map, etc.
- Difference between ArrayList and LinkedList?
- ArrayList is
array-based, LinkedList uses nodes.
Advanced Java
Questions
- What is reflection in Java?
- Inspecting and modifying classes at
runtime.
- What is Java generics?
- Allows type-safe collections
(e.g., ArrayList<String>).
- What is a Java annotation?
- Metadata added to code
(e.g., @Override).
- What is the Java memory model?
- Defines how threads interact through
memory.
- What is volatile in Java?
- Ensures variable visibility across
threads.
- What is the transient keyword?
- Excludes a field from serialization.
- What is serialVersionUID?
- A version control number for
serialization.
- What is a Java lambda expression?
- A concise way to implement functional
interfaces.
- What is the Java Stream API?
- Used for functional-style operations on collections.
- What is the Optional class in Java?
- Avoids NullPointerException by
wrapping nullable objects.
Python Programming
Interview Questions (30+ Questions)
Basic Python
Questions
- What is Python?
- An interpreted, high-level, dynamically
typed language.
- What are Python’s key features?
- Easy syntax, dynamic typing, extensive
libraries.
- What are Python lists and tuples?
- Lists are mutable, tuples are immutable.
- What is a Python dictionary?
- A key-value pair collection ({}).
- What is PEP 8?
- Python’s style guide for clean code.
- What is __init__ in Python?
- Constructor method for classes.
- What is a lambda function?
- An anonymous function (lambda x: x+1).
- What is list comprehension?
- Concise way to create lists ([x for x in
range(10)]).
- What is the difference between == and is?
- == checks value, is checks
memory location.
- What are Python decorators?
- Functions that modify other functions
(@decorator).
Intermediate Python
Questions
- What is the GIL in Python?
- Global Interpreter Lock restricts
multi-threading.
- What are Python generators?
- Functions that yield values lazily
(yield keyword).
- What is *args and **kwargs?
- *args for variable
arguments, **kwargs for keyword arguments.
- What is pickle in Python?
- Used for object serialization.
- What is __str__ vs __repr__?
- __str__ for user-friendly
output, __repr__ for debugging.
- What is zip() in Python?
- Combines multiple iterables.
- What is map() and filter()?
- map() applies a
function, filter() filters elements.
- What is a Python module?
- A file containing Python code (import
module).
- What is virtualenv?
- Creates isolated Python environments.
- What is try-except-else-finally?
- Handles exceptions in Python.
Advanced Python
Questions
- What is monkey patching?
- Modifying classes/modules at runtime.
- What is a Python metaclass?
- A class that defines other classes
(type).
- What is asyncio in Python?
- Library for asynchronous programming.
- What is collections.defaultdict?
- A dictionary with default values.
- What is __slots__?
- Optimizes memory usage in classes.
- What is @staticmethod vs @classmethod?
- @staticmethod doesn’t
take self, @classmethod takes cls.
- What is functools.partial?
- Freezes some function arguments.
- What is __call__ in Python?
- Makes an object callable like a function.
- What is __new__ vs __init__?
- __new__ creates an
object, __init__ initializes it.
- What is contextlib?
- Helps in creating context managers.
Comments
Post a Comment