The delete[] operator is used to deallocate that memory from heap that was allocated using the new[] operator. In this article, we will explore, what is delete[] operator in C++, how it works, and how it knows the size of the operand array to deallocate the correct amount of memory. The delete[] Operator The delete[] operator is a C++ operator that is used to free memory that was previously allocated for an array using the new[] operator. It is always important to deallocate memory that has been allocated with new[] to avoid memory leaks in your program. If you ... Read More
The pointers in C++ are used to store memory addresses of variables. We can perform pointer arithmetic such as incrementing or decrementing pointers to traverse through an arrays. In this article, we will learn how to using pointer arithmetic in C++ to traverse through an array and find sum of it. First of all, let's understand the problem statement. You are given an array of integers and you need to find the sum of all the elements in that array using pointer arithmetic. For example: // Input array int arr[] = {1, 2, 3, 4, 5}; ... Read More
Alpha-numeric string are the strings that containing both alphabets and numbers mixed together. These are generally used in security system for generating passwords or hash keys. In this article, we will learn all the approaches for developing a C++ program to generate random alpha numeric stiring. First of all, let's understand the problem statement, We have to input a positive integer for the length of string. The program should output a string of the size containing random characters and numbers. For example, // Input Number : Length of alpha-numeric string 5 // Output String : Alpha-numeric string fd23j ... Read More
In Python, when we are working with files that contain a large amount of data then it is often inefficient to read the entire content into memory at once. In such cases, we can read a fixed amount of data at a time by using the read() method with a specified size. This process is commonly known as buffered or chunk-based reading. The Chunk-based reading is a program to read a file piece-by-piece rather than loading it completely. This process is particularly helpful when handling large files, as it helps to reduce memory consumption and enhances performance during file processing operations. ... Read More
The given task is to list the directory tree structure, i.e., we need to print the hierarchy of folders and files starting from a specified root directory. This is similar to how the tree command works in Linux or Windows by showing nested folders and files in a structured and indented format. In this article, we will see all the possible methods in Python to list the directory tree structure. Using os.walk() Method The os.walk() method in Python is used to generate the file names and folder names in a directory tree by parsing through the tree in either a ... Read More
Python uses indentation to define blocks of code instead of curly braces or keywords. If the indentation is not correct, Python raises an IndentationError. In this article, you will learn how to catch and handle IndentationError in Python using various approaches. An IndentationError in Python occurs when the indentation rules are not followed properly. It is raised during the parsing stage, not during execution. Therefore, to catch it, you must execute the code dynamically as a string. Using exec(), compile(), and custom wrapper functions, you can catch and handle this error in Python programs. We can use the following methods ... Read More
A TypeError occurs in Python when we perform an operation on an object of an inappropriate type. For example, adding a string to an integer or calling a non-callable object. In this article, you will learn how to catch and handle TypeError exceptions using different methods in Python. TypeError is raised when you use the wrong data type in an operation. You can handle this exception using try-except blocks to prevent the program from crashing and help you correct input. Always test your code where type mismatches are possible, especially when working with user input or dynamic data. There are ... Read More
In Python, the EnvironmentError occurs when errors related to the system's environment, such as file I/O issues or hardware failures, occur. In the latest Python versions (i.e., 3.3+), this exception is the same as OSError. In this article, you will learn how to catch EnvironmentError (or OSError) to handle system-level errors and prevent programs from crashing abruptly. Some of the common reasons to catch EnvironmentError are - When a file operation fails When a directory cannot be accessed or found When a hardware or device-related issue occurs Using try-except to Catch EnvironmentError To catch EnvironmentError, use a try-except ... Read More
The size of a pointer in C/C++ is not fixed. It depends upon different issues like Operating system, CPU architecture etc. Usually it depends upon the word size of underlying processor, for example for a 32 bit computer the pointer size can be 4 bytes and for a 64 bit computer the pointer size can be 8 bytes. So for a specific architecture pointer size will be fixed. It is common to all data types like int *, float * etc. Depending on the system architecture, pointer size may vary. The following table shows the pointer size based on the ... Read More
An array is a collection of elements of the same type such as integers, string, etc. Array in STL In C++ Standard Template Library (STL) , we use std::array container to create arrays with a fixed size. the size cannot be changed once created. It works like a normal array but with extra features like knowing its own size and working with STL functions. Syntax Following is the syntax to create an array in C++ STL: array(data_type, size) array_name = {va1, val2, ...valn}; Here, data_type: It specifies the type of data array will accept. it can be any ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP