Interview questions in C, Java and Python

 

C Programming Interview Questions (30+ Questions)

Basic C Questions

  1. What is C language?
    • C is a procedural, mid-level programming language developed by Dennis Ritchie in 1972.
  2. What are the key features of C?
    • Portability, efficiency, modularity, and low-level memory access.
  3. What is a pointer in C?
    • A pointer is a variable that stores the memory address of another variable.
  4. What is the difference between malloc() and calloc()?
    • malloc() allocates memory without initialization, while calloc() initializes memory to zero.
  5. 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).
  6. Explain const keyword in C.
    • It makes a variable read-only (immutable).
  7. What is a dangling pointer?
    • A pointer pointing to a deallocated memory location.
  8. What is recursion? Give an example.
    • A function calling itself (e.g., factorial calculation).
  9. Difference between ++i and i++?
    • ++i is pre-increment, i++ is post-increment.
  10. What is a header file in C?
    • Contains function declarations and macros (e.g., stdio.h).

Intermediate C Questions

  1. What is a structure in C?
    • A user-defined data type that groups different data types.
  2. What is a union in C?
    • Similar to a structure but shares memory for all members.
  3. What is the difference between struct and union?
    • Struct allocates separate memory for each member; union shares memory.
  4. What is typedef in C?
    • Used to create an alias for a data type.
  5. What is volatile keyword in C?
    • Prevents compiler optimization for variables that may change unexpectedly.
  6. What is a memory leak?
    • When dynamically allocated memory is not freed, causing wasted memory.
  7. What is #pragma in C?
    • A compiler directive for special instructions.
  8. Explain sizeof() operator.
    • Returns the size (in bytes) of a variable or data type.
  9. What is a function pointer?
    • A pointer that points to a function instead of a variable.
  10. What is strtok() in C?
    • Used to split strings into tokens.

Advanced C Questions

  1. What is the difference between memcpy() and memmove()?
    • memmove() handles overlapping memory regions; memcpy() does not.
  2. What is a far pointer?
    • Used in segmented architectures to access memory outside the current segment.
  3. What is a null pointer?
    • A pointer that does not point to any valid memory location (NULL).
  4. What is a void pointer?
    • A generic pointer that can point to any data type.
  5. What is the difference between #include <file.h> and #include "file.h"?
    • <file.h> searches in system directories, "file.h" searches in local directories.
  6. What is a bit field in C?
    • A data structure that stores data in bits.
  7. What is restrict keyword in C?
    • Indicates that a pointer is the only way to access the memory it points to.
  8. What is setjmp() and longjmp()?
    • Used for non-local jumps in C.
  9. What is a file descriptor in C?
    • An integer representing an open file.
  10. What is errno in C?
    • A global variable indicating error codes.

Java Programming Interview Questions (40+ Questions)

Basic Java Questions

  1. What is Java?
    • An object-oriented, platform-independent programming language.
  2. What is JVM?
    • Java Virtual Machine executes Java bytecode.
  3. Difference between JDK, JRE, and JVM?
    • JDK (Development Kit), JRE (Runtime Environment), JVM (Execution Engine).
  4. What is the main method in Java?
    • Entry point of a Java program (public static void main(String[] args)).
  5. What are Java access modifiers?
    • public, private, protected, and default (package-private).
  6. What is method overloading?
    • Multiple methods with the same name but different parameters.
  7. What is method overriding?
    • Redefining a parent class method in a child class.
  8. What is the final keyword in Java?
    • Makes a variable constant, a method non-overridable, or a class non-inheritable.
  9. What is a constructor?
    • A special method called when an object is created.
  10. What is the difference between == and .equals()?
    • == checks reference, .equals() checks content.

Intermediate Java Questions

  1. What is the difference between StringStringBuilder, and StringBuffer?
    • String is immutable, StringBuilder is mutable & not thread-safe, StringBuffer is thread-safe.
  2. What is exception handling in Java?
    • Using try-catch-finally blocks to handle runtime errors.
  3. What are checked and unchecked exceptions?
    • Checked (compile-time, e.g., IOException), Unchecked (runtime, e.g., NullPointerException).
  4. What is multithreading in Java?
    • Running multiple threads simultaneously.
  5. Difference between extends and implements?
    • extends for inheritance, implements for interfaces.
  6. What is a singleton class?
    • A class that allows only one instance.
  7. What is the static keyword in Java?
    • Belongs to the class rather than instances.
  8. What is garbage collection in Java?
    • Automatic memory management by JVM.
  9. What are Java collections?
    • Frameworks like List, Set, Map, etc.
  10. Difference between ArrayList and LinkedList?
    • ArrayList is array-based, LinkedList uses nodes.

Advanced Java Questions

  1. What is reflection in Java?
    • Inspecting and modifying classes at runtime.
  2. What is Java generics?
    • Allows type-safe collections (e.g., ArrayList<String>).
  3. What is a Java annotation?
    • Metadata added to code (e.g., @Override).
  4. What is the Java memory model?
    • Defines how threads interact through memory.
  5. What is volatile in Java?
    • Ensures variable visibility across threads.
  6. What is the transient keyword?
    • Excludes a field from serialization.
  7. What is serialVersionUID?
    • A version control number for serialization.
  8. What is a Java lambda expression?
    • A concise way to implement functional interfaces.
  9. What is the Java Stream API?
    • Used for functional-style operations on collections.
  10. What is the Optional class in Java?
    • Avoids NullPointerException by wrapping nullable objects.

Python Programming Interview Questions (30+ Questions)

Basic Python Questions

  1. What is Python?
    • An interpreted, high-level, dynamically typed language.
  2. What are Python’s key features?
    • Easy syntax, dynamic typing, extensive libraries.
  3. What are Python lists and tuples?
    • Lists are mutable, tuples are immutable.
  4. What is a Python dictionary?
    • A key-value pair collection ({}).
  5. What is PEP 8?
    • Python’s style guide for clean code.
  6. What is __init__ in Python?
    • Constructor method for classes.
  7. What is a lambda function?
    • An anonymous function (lambda x: x+1).
  8. What is list comprehension?
    • Concise way to create lists ([x for x in range(10)]).
  9. What is the difference between == and is?
    • == checks value, is checks memory location.
  10. What are Python decorators?
    • Functions that modify other functions (@decorator).

Intermediate Python Questions

  1. What is the GIL in Python?
    • Global Interpreter Lock restricts multi-threading.
  2. What are Python generators?
    • Functions that yield values lazily (yield keyword).
  3. What is *args and **kwargs?
    • *args for variable arguments, **kwargs for keyword arguments.
  4. What is pickle in Python?
    • Used for object serialization.
  5. What is __str__ vs __repr__?
    • __str__ for user-friendly output, __repr__ for debugging.
  6. What is zip() in Python?
    • Combines multiple iterables.
  7. What is map() and filter()?
    • map() applies a function, filter() filters elements.
  8. What is a Python module?
    • A file containing Python code (import module).
  9. What is virtualenv?
    • Creates isolated Python environments.
  10. What is try-except-else-finally?
    • Handles exceptions in Python.

Advanced Python Questions

  1. What is monkey patching?
    • Modifying classes/modules at runtime.
  2. What is a Python metaclass?
    • A class that defines other classes (type).
  3. What is asyncio in Python?
    • Library for asynchronous programming.
  4. What is collections.defaultdict?
    • A dictionary with default values.
  5. What is __slots__?
    • Optimizes memory usage in classes.
  6. What is @staticmethod vs @classmethod?
    • @staticmethod doesn’t take self, @classmethod takes cls.
  7. What is functools.partial?
    • Freezes some function arguments.
  8. What is __call__ in Python?
    • Makes an object callable like a function.
  9. What is __new__ vs __init__?
    • __new__ creates an object, __init__ initializes it.
  10. What is contextlib?
    • Helps in creating context managers.

 

Comments

Popular posts from this blog

How to Get a Job in Top IT MNCs (TCS, Infosys, Wipro, Google, etc.) – Step-by-Step Guide for B.Tech Final Year Students

Common HR Interview Questions

How to Get an Internship in a MNC