Skip to content
  • Home
  • Software Engineering Jobs
  • Internship Opportunities
  • Remote Jobs
  • Layoffs Tracker
  • Interview Preparation
  • Resume Score Checker
  • Tech News
logo1
  • Software Engineering Jobs
  • Latest Jobs
  • Internships
  • Remote Job
  • Interview Preparation
  • Paid courses
  • Technology News

Programming Language Interview

Devops Interview Questions

Programming Interview Questions

Question Answer
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 a block of memory without initializing it, while `calloc()` allocates memory and initializes all bytes to 0.
What is a structure in C? A structure is a user-defined data type in C that allows grouping different types of data items together.
What is the difference between `++i` and `i++`? `++i` is pre-increment, meaning the value is incremented before being used. `i++` is post-increment, meaning the value is used before being incremented.
What is a segmentation fault? A segmentation fault occurs when a program tries to access restricted or non-existent memory areas.
What is the difference between `struct` and `union`? In a `struct`, each member has its own memory location, whereas in a `union`, all members share the same memory location.
What is a static variable? A static variable retains its value between function calls and is initialized only once during the program’s execution.
What is the use of the `const` keyword? The `const` keyword is used to define variables that cannot be modified after initialization.
What is the purpose of the `sizeof()` operator? The `sizeof()` operator is used to determine the size, in bytes, of a data type or a variable.
What is a function pointer? A function pointer is a pointer that points to a function in memory, allowing dynamic function calls.
What is recursion? Recursion is a process where a function calls itself in order to solve a problem in smaller sub-problems.
What is the purpose of `return` in C? The `return` statement is used to exit from a function and optionally return a value to the caller.
What are header files in C? Header files in C are files with a `.h` extension that contain function declarations, macros, and structure definitions used in programs.
What is the difference between `==` and `=`? `==` is the equality operator used to compare values, while `=` is the assignment operator used to assign values to variables.
What is the difference between C++ and C? C++ is an extension of C that includes object-oriented programming features like classes and objects, whereas C is a procedural language.
What are constructors in C++? A constructor is a special member function that initializes an object when it is created.
What is the purpose of destructors in C++? A destructor is a special member function that is called when an object is destroyed, and it is used to clean up resources allocated by the object.
What is the difference between function overloading and function overriding? Function overloading is defining multiple functions with the same name but different parameters. Function overriding is redefining a function in a derived class with the same signature as in the base class.
What is the purpose of the `virtual` keyword? The `virtual` keyword is used to create functions that can be overridden in derived classes, enabling polymorphism.
What is the difference between public, private, and protected access specifiers? Public members are accessible from anywhere, private members are only accessible within the class, and protected members are accessible within the class and derived classes.
What is polymorphism in C++? Polymorphism allows different objects to be treated as instances of the same class through inheritance, enabling a single interface to represent different types.
What is an abstract class? An abstract class is a class that cannot be instantiated, and it typically contains at least one pure virtual function.
What is the difference between static and dynamic binding? Static binding is determined at compile-time, while dynamic binding is resolved at runtime, typically through virtual functions.
What are templates in C++? Templates allow functions and classes to operate with generic types, enabling code reuse for different data types.
What is the difference between a class and a structure in C++? In C++, structures default to public access, while classes default to private access.
What is the purpose of the `new` and `delete` operators? `new` is used to allocate memory dynamically, while `delete` is used to free the memory allocated by `new`.
What is the difference between `&` and `&&` in C++? `&` is used to declare a reference to a variable, while `&&` is used for rvalue references, often in move semantics.
What are exceptions in C++? Exceptions are mechanisms to handle runtime errors through the `try`, `throw`, and `catch` blocks, enabling graceful error handling.
What is Object-Oriented Programming (OOP)? OOP is a programming paradigm that uses objects and classes to organize code and data. It focuses on key principles like inheritance, encapsulation, polymorphism, and abstraction.
What is a class in OOP? A class is a blueprint for creating objects. It defines properties (variables) and behaviors (methods) that an object of that class will have.
What is an object in OOP? An object is an instance of a class. It represents a specific entity with attributes and methods defined by the class.
What is inheritance in OOP? Inheritance allows a class to inherit properties and methods from another class. The derived class can extend or override the functionality of the base class.
What is polymorphism in OOP? Polymorphism allows objects of different classes to be treated as objects of a common base class. It enables methods to be called on objects of different types using the same interface.
What is encapsulation in OOP? Encapsulation is the bundling of data and the methods that operate on the data into a single unit or class. It hides the internal workings of the class and exposes only necessary details through public methods.
What is abstraction in OOP? Abstraction is the concept of hiding the complex implementation details of an object and exposing only essential features. It allows the user to focus on what an object does, rather than how it does it.
What is a constructor in OOP? A constructor is a special member function of a class that is automatically called when an object is created. It initializes the object's data members.
What is a destructor in OOP? A destructor is a special member function of a class that is automatically called when an object is destroyed. It is used to free any resources allocated to the object.
What is the difference between method overloading and method overriding? Method overloading is defining multiple methods with the same name but different parameters. Method overriding is redefining a method in a derived class that was already defined in the base class.
What is the purpose of the 'virtual' keyword in C++? The 'virtual' keyword is used to enable dynamic (runtime) polymorphism. It tells the compiler to use the function in the derived class, even if it is called through a pointer or reference to the base class.
What is an abstract class in OOP? An abstract class is a class that cannot be instantiated and is intended to be used as a base class. It may have pure virtual functions, which must be implemented by derived classes.
What is multiple inheritance in C++? Multiple inheritance is a feature in C++ where a class can inherit from more than one base class, which allows the derived class to inherit attributes and methods from multiple classes.
What is the difference between 'public', 'private', and 'protected' inheritance? In public inheritance, the public and protected members of the base class become public and protected in the derived class. In private inheritance, they become private in the derived class. In protected inheritance, they become protected in the derived class.
What is the difference between `var`, `let`, and `const` in JavaScript? `var` is function-scoped and can be re-assigned. `let` is block-scoped and can also be re-assigned. `const` is block-scoped but cannot be re-assigned after initialization.
What is a closure in JavaScript? A closure is a function that remembers and can access variables from the outer scope even after the outer function has finished executing.
What is event delegation in JavaScript? Event delegation is a technique where you attach a single event listener to a parent element to manage events for its child elements, reducing the number of event listeners required.
What is the difference between `==` and `===` in JavaScript? `==` performs a type coercion before comparing values, while `===` checks for both value and type equality without type coercion.
What is a promise in JavaScript? A promise is an object representing the eventual completion or failure of an asynchronous operation and its resulting value. It allows handling asynchronous results in a more readable way than callbacks.
What are arrow functions in JavaScript? Arrow functions provide a concise syntax for writing functions. They do not have their own `this`, and instead inherit `this` from the parent scope.
What is the event loop in JavaScript? The event loop is the mechanism that allows JavaScript to handle asynchronous tasks by continuously checking the message queue for events to execute.
What are JavaScript data types? JavaScript has seven primitive data types: `undefined`, `null`, `boolean`, `number`, `bigint`, `string`, and `symbol`. There is also one non-primitive data type: `object`.
What is the `this` keyword in JavaScript? The `this` keyword refers to the context in which a function is called, and it can refer to different objects depending on how the function is invoked.
What is the difference between `null` and `undefined` in JavaScript? `null` is an assignment value representing "no value" or "empty," while `undefined` is a variable that has been declared but not assigned any value.
What are template literals in JavaScript? Template literals allow embedding expressions inside string literals using backticks (`` ` ``), and they can include multiline strings and string interpolation using `${expression}`.
What is a JavaScript callback function? A callback function is a function passed as an argument to another function that is executed after the completion of an operation or event.
What is destructuring in JavaScript? Destructuring is a syntax feature that allows unpacking values from arrays or properties from objects into distinct variables.
What is the spread operator in JavaScript? The spread operator (`...`) allows you to unpack elements from an array or object, enabling easier copying, combining, and passing of elements.
What is the difference between synchronous and asynchronous code in JavaScript? Synchronous code is executed line by line, blocking further execution, while asynchronous code allows other operations to run while waiting for a task (such as a network request) to complete.
What are the different ways to create objects in JavaScript? Objects in JavaScript can be created using object literals (`{}`), `new Object()`, or via constructor functions and classes.
What is the `bind()` method in JavaScript? The `bind()` method creates a new function that, when invoked, has its `this` keyword set to the provided value, and can also have a set of arguments prepended to the function call.
What is a higher-order function in JavaScript? A higher-order function is a function that either takes one or more functions as arguments or returns a function as its result.
What are JavaScript modules? JavaScript modules allow you to separate your code into smaller files and import/export functions or variables between them. They help in organizing code and improving maintainability.
What is the `fetch()` API in JavaScript? The `fetch()` API is used to make asynchronous HTTP requests to servers. It returns a `Promise` that resolves to the `Response` to that request, allowing you to handle the response data.
What is the `async/await` syntax in JavaScript? The `async/await` syntax is a modern way to handle asynchronous code in JavaScript. The `async` keyword is used to define an asynchronous function, and the `await` keyword is used to pause the execution of an async function until a `Promise` is settled.
What is the `localStorage` object in JavaScript? The `localStorage` object allows you to store key-value pairs in the browser's local storage, persisting data even after the browser is closed or refreshed.
What is the `sessionStorage` object in JavaScript? The `sessionStorage` object is similar to `localStorage`, but the data stored in `sessionStorage` is cleared when the page session ends (i.e., when the browser tab is closed).
What is the `map()` method in JavaScript? The `map()` method creates a new array by calling a provided function on every element in the calling array. It does not mutate the original array.
What is the `filter()` method in JavaScript? The `filter()` method creates a new array with all elements that pass the test implemented by the provided function. It does not mutate the original array.
What is the `reduce()` method in JavaScript? The `reduce()` method applies a function against an accumulator and each element in the array (from left to right) to reduce it to a single value. It does not mutate the original array.
What is the `find()` method in JavaScript? The `find()` method returns the first element in an array that satisfies a provided testing function. It does not mutate the original array.
What is the `sort()` method in JavaScript? The `sort()` method sorts the elements of an array in place and returns the sorted array. The default sort order is ascending.
What is the `forEach()` method in JavaScript? The `forEach()` method executes a provided function once for each array element. It does not mutate the original array.
What is the `some()` method in JavaScript? The `some()` method tests whether at least one element in the array passes the test implemented by the provided function. It returns `true` if any element passes the test, otherwise `false.
What is Node.js? Node.js is an open-source, cross-platform runtime environment that allows you to run JavaScript code on the server side. It uses Google's V8 JavaScript engine to execute code.
Why use Node.js? Node.js is popular for building fast, scalable network applications due to its non-blocking I/O model and single-threaded event loop, making it suitable for real-time applications.
What is the event loop in Node.js? The event loop in Node.js is the mechanism that handles asynchronous operations. It allows Node.js to perform non-blocking operations by handling callbacks and events in a queue.
What is npm? npm (Node Package Manager) is the default package manager for Node.js. It helps in managing dependencies and modules in Node.js applications, and it is used to install and manage JavaScript libraries.
What is a callback in Node.js? A callback is a function passed as an argument to another function that is executed once the operation is completed. It is a common way to handle asynchronous operations in Node.js.
What is the difference between `require()` and `import` in Node.js? `require()` is used to import modules in Node.js in CommonJS format, whereas `import` is used in ES6 modules for importing modules, which is supported in modern JavaScript.
What is Express.js? Express.js is a lightweight and flexible Node.js framework used for building web applications and APIs. It simplifies routing and middleware integration.
What is middleware in Express.js? Middleware in Express.js are functions that have access to the request, response, and the next middleware in the application’s request-response cycle. They perform tasks such as logging, authentication, or handling errors.
What is the difference between synchronous and asynchronous code in Node.js? Synchronous code blocks the execution of subsequent lines of code until it completes, whereas asynchronous code allows other tasks to be executed while waiting for an operation to complete.
What is `process.nextTick()`? `process.nextTick()` is used to schedule a callback function to be invoked in the next iteration of the event loop, before any I/O events.
What is a promise in Node.js? A promise is an object that represents the eventual completion or failure of an asynchronous operation. It provides a cleaner alternative to callbacks for handling asynchronous code.
What is the purpose of the `fs` module in Node.js? The `fs` (File System) module provides an API for interacting with the file system, allowing you to read, write, and manipulate files and directories.
What are Streams in Node.js? Streams are objects that allow reading or writing data in a continuous manner. Node.js streams support both reading and writing files, network communications, or any kind of end-to-end information exchange.
What are the types of streams in Node.js? Node.js has four types of streams: Readable streams (for reading), Writable streams (for writing), Duplex streams (for both reading and writing), and Transform streams (for modifying data as it is read or written).
What is clustering in Node.js? Clustering allows you to create child processes that can share server ports. This can be used to take advantage of multi-core systems and increase the performance of a Node.js application.
What is the role of the `http` module in Node.js? The `http` module allows you to create HTTP servers and handle HTTP requests and responses, enabling you to build web servers and APIs in Node.js.
What is the `Buffer` class in Node.js? The `Buffer` class is used to handle binary data directly in memory. It allows you to work with raw binary data, such as reading files or network streams.
What is the purpose of `async` and `await` in Node.js? `async` and `await` are used for writing asynchronous code in a synchronous manner. `async` makes a function return a promise, and `await` is used to pause execution until the promise is resolved.
What is the `cluster` module in Node.js? The `cluster` module allows Node.js to create child processes that share the same server port. It enables better use of multi-core processors for Node.js applications.
What is the purpose of the `EventEmitter` class in Node.js? The `EventEmitter` class is used to handle events in Node.js. It allows you to emit events and listen for those events in your application, which is essential for creating event-driven systems.
What is the use of the `global` object in Node.js? The `global` object in Node.js provides a global namespace that can be accessed from any module in the application. It contains objects like `process`, `__dirname`, `__filename`, and others.
What are the advantages of using Node.js? Node.js is lightweight, efficient, and scalable. It uses an event-driven, non-blocking I/O model that makes it suitable for building real-time, data-intensive applications.
What is `node package manager` (npm) registry? The npm registry is a public repository where you can find and publish open-source Node.js packages. It provides a way to manage packages, dependencies, and modules for Node.js applications.
What is the purpose of the `process` object in Node.js? The `process` object provides information about the current Node.js process, such as environment variables, command-line arguments, memory usage, and the ability to handle signals and exit events.
What is a WebSocket and how is it used in Node.js? WebSockets provide full-duplex communication channels over a single TCP connection. In Node.js, the `ws` module can be used to create WebSocket servers and clients for real-time communication between a server and browser.
What is the difference between `fs.readFile()` and `fs.createReadStream()`? `fs.readFile()` reads the entire file into memory at once, while `fs.createReadStream()` creates a stream of the file's data, allowing you to process the file's contents chunk by chunk without loading it entirely into memory.
What is the purpose of the `crypto` module in Node.js? The `crypto` module provides cryptographic functionalities, such as hashing, encryption, decryption, and secure random number generation, useful for securing data in Node.js applications.
What is a callback hell in Node.js? Callback hell refers to the nested structure of callback functions in asynchronous code, making the code difficult to read and maintain. This problem can be mitigated by using Promises or `async`/`await`.
What is the purpose of `setTimeout()` in Node.js? `setTimeout()` is used to execute a function after a specified delay (in milliseconds). It's often used for scheduling one-off tasks or delays between operations in Node.js applications.
What is `require.cache` in Node.js? `require.cache` is an object that stores cached modules that have already been loaded. This helps avoid loading the same module multiple times and improves performance.
What is a `stream` in Node.js? A stream is an abstract interface for working with streaming data, which can be either readable or writable. Streams allow for processing data piece-by-piece without reading it all into memory at once.
What is the difference between `spawn()` and `exec()` in Node.js? `spawn()` is used to launch new processes with a stream-based interface, while `exec()` runs a command in a shell and buffers the output before returning it as a callback.
What is the `cluster` module and how does it work? The `cluster` module allows you to create child processes that share the same server port. It enables the use of multiple CPU cores to handle parallel workloads, improving performance in multi-core environments.
What are the differences between `var`, `let`, and `const` in Node.js? `var` is function-scoped and can be re-assigned. `let` is block-scoped and can also be re-assigned. `const` is block-scoped but cannot be re-assigned after initialization.
What is the `buffer` module in Node.js? The `buffer` module allows you to work with raw binary data directly in memory, which is necessary for tasks such as handling binary streams or reading files that contain non-textual data.
What is the `path` module in Node.js? The `path` module provides utilities for working with and manipulating file and directory paths, such as joining, resolving, and normalizing file paths.
What is the role of `node-gyp`? `node-gyp` is a tool used to compile native C++ modules for Node.js. It’s necessary for building modules that require native compilation, such as those that depend on libraries like `libv8` or `openssl`.
What is the event loop in JavaScript? The event loop is a mechanism that allows JavaScript to execute asynchronous code, enabling non-blocking behavior. It continuously checks the message queue for events to process and executes them sequentially, while ensuring the execution of synchronous code first.
What are the phases of the event loop in JavaScript? The event loop has multiple phases:
  • Execution of any currently executing synchronous code (call stack)
  • Execution of messages/events in the message queue (callback queue)
  • Executing microtasks (e.g., promises)
What is the difference between the call stack and the message queue? The call stack holds the execution contexts of all synchronous code that is being executed. The message queue, also known as the task queue, holds events and callbacks that are ready to be executed once the call stack is empty.
What is a non-blocking operation in JavaScript? Non-blocking operations allow the program to continue executing while waiting for a task to complete, such as an API request or I/O operation. This is achieved using callbacks, promises, and async/await.
How does JavaScript handle asynchronous code? JavaScript uses the event loop to handle asynchronous code. Asynchronous tasks are placed in the message queue, while synchronous tasks are executed on the call stack. The event loop picks up tasks from the queue once the call stack is empty.
What is the difference between `setTimeout()` and `setInterval()` in terms of event loop? `setTimeout()` schedules a single execution of a callback after a specified delay, while `setInterval()` repeatedly executes the callback after a specified interval. Both of these methods use the event loop to execute the callback asynchronously.
What is the role of the microtask queue in the event loop? The microtask queue holds tasks like promises that need to be executed after the currently executing script but before any other events in the message queue. It allows for the immediate resolution of promises.
How does JavaScript ensure non-blocking I/O operations? JavaScript ensures non-blocking I/O by using asynchronous callbacks, promises, and the event loop to handle operations like network requests and file system access without blocking the main thread.
What is the purpose of the `async` and `await` keywords in JavaScript? `async` and `await` are used to handle asynchronous operations in a more readable and synchronous-like manner. `async` marks a function as asynchronous, and `await` pauses the execution of the function until the promise is resolved.
What is the role of the event loop in handling promises in JavaScript? The event loop processes promises after the currently executing synchronous code has finished. Promises are placed in the microtask queue, and the event loop ensures they are resolved before processing other events from the message queue.
Can JavaScript run multiple tasks concurrently? JavaScript is single-threaded, meaning it cannot run multiple tasks at the same time. However, asynchronous tasks can be run concurrently by using the event loop, which allows tasks to be scheduled without blocking the main thread.
What happens if the event loop is blocked in JavaScript? If the event loop is blocked, asynchronous code will not be executed, and the application will become unresponsive. This happens if a long-running synchronous task is blocking the call stack, preventing the event loop from processing other events or callbacks.
What is a callback function, and how does it relate to the event loop? A callback function is a function passed as an argument to another function. When an asynchronous operation is completed, the callback is added to the message queue, and the event loop processes it once the call stack is empty.
What is a promise and how does it interact with the event loop? A promise represents an asynchronous operation that will eventually resolve or reject. Once a promise is resolved or rejected, its `.then()` or `.catch()` callbacks are pushed to the microtask queue, which the event loop processes before other events.
What happens if you add a large number of synchronous tasks to the call stack? If you add a large number of synchronous tasks to the call stack, it can block the event loop, preventing asynchronous tasks from executing. This can lead to performance issues or the application freezing.
Can the event loop handle both asynchronous and synchronous tasks? Yes, the event loop handles both synchronous tasks (on the call stack) and asynchronous tasks (from the message queue and microtask queue), processing them in order of priority and availability.
What is the difference between `setImmediate()` and `process.nextTick()` in Node.js? `setImmediate()` schedules a callback to be executed after the current event loop cycle, while `process.nextTick()` schedules the callback to be executed immediately after the current operation completes, before any other event loop tasks.

© 2025 Geeksprep

  • Privacy Policy
  • Terms of Use
  • DMCA
  • CCPA