How to initialize const member variable in a C++ class?

Tapas Kumar Ghosh
Updated on 11-Jun-2025 16:42:41

17K+ Views

A const member variable in a C++ class is a data member whose value must be initialized during object construction and cannot be modified. Initializing Const Member Variable in C++ Class The const member variable must be initialized. To initialize a const member variable, you can use a member initializer list using a constructor, . The member initializer list is the special way to initialize the values to class variables while creating an object before the constructor block runs. Note: If the member is static and of an integer type, you can directly initialized with the class definition. ... Read More

How to check if text is “empty” (spaces, tabs, newlines) in Python?

Sarika Singh
Updated on 11-Jun-2025 15:38:27

4K+ Views

In this article, we are going to focus on how to check if the text is empty (spaces, tabs, newlines) in Python. Checking if text is Empty using isspace() method The isspace() method determines whether a string contains only spaces or contains any other characters. If the given string is only made up of spaces, this method returns true; otherwise, it returns false. Even if the string contains characters like t and n, the method returns true. Example In the program given below, we are taking 3 different strings and finding out if they contain only spaces using the isspace() ... Read More

How to insert new keys/values into Python dictionary?

Niharikaa Aitam
Updated on 11-Jun-2025 15:26:06

65K+ Views

A dictionary in Python is a mutable, unordered collection of key-value pairs.Inserting keys/values into a Python dictionaryWe can add new key-value pairs to an existing dictionary simply by assigning a value to a new key. In this article, we are going to explore the different ways to insert new key values into a Python dictionary. Following is an example, which creates a dictionary with 4 key-value pairs and displays the dictionary - # Creating a Dictionary with 4 key-value pairs myprod = { "Product":"Mobile", "Model": "XUT", "Units": 120, "Available": "Yes" } # Displaying the Dictionary print(myprod) # Displaying ... Read More

What is Array Decay in C++?

Nishu Kumari
Updated on 11-Jun-2025 15:17:11

2K+ Views

The loss of type and dimensions of an array is known as array decay. It occurs when we pass the array into a function by pointer or by value. Only the address of the first element is sent, which is treated as a pointer. As a result, the original array's size and type information are lost. Because of this decay, sizeof no longer gives the full size of the array but instead returns the size of the pointer. This can cause incorrect behavior in functions that depend on knowing the number of elements. Example of Array ... Read More

What is the use of cin.ignore() in C++?

Nishu Kumari
Updated on 11-Jun-2025 15:09:43

67K+ Views

In C++, cin.ignore() is a built-in function that belongs to the istream class and is defined in the header. It is used to skip characters left in the input buffer, especially the newline character (''), which can cause issues with input operations like getline(). In this article, we will explain the use of cin.ignore() in C++. Syntax of cin.ignore() Below is the syntax of the cin.ignore() function. cin.ignore(numeric_value, delimiter_char); // Example: cin.ignore(1000, ''); Here, numeric_value is the maximum number of characters to skip, and delimiter_char is the character at which the input should stop ... Read More

Get similar words suggestion using Enchant in Python

Sumana Challa
Updated on 11-Jun-2025 14:57:14

409 Views

There will be times when we misspell some words when we write something. To overcome this problem, we use the PyEnchant module in Python. This module is used to check the spelling of words and suggest corrections that are misspelled words. It is also used in many popular tasks, including ispell, aspell, and MySpell. It is very flexible in handling multiple dictionaries and multiple languages. For example, if the input is 'prfomnc', then the output returned would be - 'prominence', 'performance', 'preform', 'provence', 'preferment', 'proforma'. PyEnchant Module For Windows users, install the pre-built binary packages using pip - pip ... Read More

Minkowski distance in Python

Sumana Challa
Updated on 11-Jun-2025 14:47:47

2K+ Views

Minkowski distance is a metric in a normed vector space that measures the distance between two or more vectors. This is typically used in machine learning to find distance similarity. The formula to calculate the Minkowski distance is - $$\mathrm{D= \big[\sum_{i=1}^{n}|r_i-s_i|^p\big]^{1/p}}$$ Where, xi and yi: Two points in n-dimensional space p: Parameter that determines the type of distance being calculated. For example, if p=1, it is the Manhattan distance, and if p=2, it represents Euclidean distance. For example, if we consider the following vector's as input - x = (0, ... Read More

How to use POSIX semaphores in C language

Tapas Kumar Ghosh
Updated on 11-Jun-2025 14:42:30

2K+ Views

The POSIX stands for Portable Operating System which was developed by IEEE (Institute of Electrical and Electronics Engineers). This is UNIX based operating system that is used for both system calls and library functions. The semaphores are used in the process of multithreading and synchronization. For eg. file sharing and memory management. It can be named or unnamed. Multithreading is the process of executing multiple tasks in the same instance of time while synchronization is used to control the thread to work in a sequential manner. It is important for data security. Using Semaphores in C language To use ... Read More

How to get current date and time in Python?

Nikitasha Shrivastava
Updated on 11-Jun-2025 14:38:02

1K+ Views

In this article, we will show you how you can get the current time and date in Python with the help of different functions. Here are the different ways to get the current Date and Time using the Datetime Module - Using the now() Method Using the today() Method Current ... Read More

How to get timer ticks at a given time in Python?

Nikitasha Shrivastava
Updated on 11-Jun-2025 14:26:35

2K+ Views

In this article, we will show you how you can get the timer ticks at the given time using different functions in Python. To get the timer ticks at the given time, there is a time module available in Python. Here is the list of ways to solve this problem - Using time.time() Function Using time.perf_counter() Function Using time.process_time() Function Let us discuss each of these methods one by one in the section below - Using time.time() Function The time.time() function is used to get the current time in seconds. It returns the number of seconds since the ... Read More

Advertisements