How to find length of a string without string.h and loop in C?

Aman Kumar
Updated on 04-Jun-2025 18:53:35

657 Views

C provides libraries for string operations such as the string.h header file that contains a strlen() function, which counts the length of a string. Otherwise, a loop can be used to count the string length. There are also different ways to find the length of a string apart from the above two methods. So, basically, in this article, we will learn how to find the length of a string without string.h and loop in C. Find Length of a String Without string.h and Loop in C There are the following ways to find the string's length without using the string.h ... Read More

Insertion and Deletion in STL Set C++

Farhan Muhamed
Updated on 04-Jun-2025 18:48:48

1K+ Views

The STL set is a container that stores unique elements in a sorted order. Insertions and deletions are common operations performed in containers like std::set and std::vector. In this article, we will learn how to insert and delete elements in a C++ STL set. Insertion in STL Set To insert a new element into a std::set you can use the insert method or the emplace method. Let's understand how to use these methods with examples. Using insert Method Using emplace Method 1. Using insert Method The insert ... Read More

How to convert std::string to lower case in C++?

Farhan Muhamed
Updated on 04-Jun-2025 18:48:16

9K+ Views

The STL library in C++ provides various inbuilt functions and methods to manipulate strings, such as converting them to lower case or upper case. In this article, we will learn all the approaches to convert a std::string to lower case in C++. First of all, let's understand the problem statement. In this problem, you are given a string as input and you need to convert it to lower case. The string may contain any type of characters such as letters, digits, and special characters. For example: // Input String std::string str = "Hello World! 123 @ TutorialsPoint"; // ... Read More

C++ Program to Find the peak element of an array using Binary Search approach

Ravi Ranjan
Updated on 04-Jun-2025 18:42:56

998 Views

The peak element in an array is an element that is greater than its neighbor elements i.e., its left and right element. If the peak element is the starting element, then it should be greater than the next element (second element). If the peak element is the last element, then it should be greater than its previous value i.e., the second last element. In this article, we have an array of integers. Our task is to use the binary search algorithm to find the peak element present in the given array. Example Here are two examples to understand the ... Read More

How to convert std::string to LPCSTR in C++?

Aman Kumar
Updated on 04-Jun-2025 17:51:29

4K+ Views

std::string The std::string is a class of C++ Standard Library (STL) that represents a string (sequence of characters). It is used to handle strings with better memory management, i.e., it provides dynamic memory management for strings and supports a rich set of in-built functions for string manipulation. Syntax Following is the syntax of string: string str = "tutorialspoint"; std::LPCSTR LPCSTR stands for Long Pointer to Constant String. It is a constant, null-terminated string of ANSI (narrow) characters (8-bit characters). In contrast to LPCWSTR, which stores wide characters (Unicode/UTF-16), LPCSTR is used in Windows API functions to store regular char-based ... Read More

Design a queue data structure to get minimum or maximum in O(1) time

Tapas Kumar Ghosh
Updated on 04-Jun-2025 17:48:39

940 Views

In data structure & algorithm, we have a deque header file that handles the properties of stack and queue. For getting minimum and maximum value from O(1) time complexity, we need constant time. So, deque is one of the possible advantages of using both stack and queue. O(1) Time Complexity The O(1) time complexity is also known as constant time which defines an algorithm for taking the same amount of time instead of using size input. Syntax The basic syntax of deque data structure is as follows: deque name_of_queue; Here, deque : It ... Read More

What is the correct way to use printf to print a size_t in C/C++?

Tapas Kumar Ghosh
Updated on 04-Jun-2025 17:41:51

25K+ Views

We should use "%zu" to print the variables of size_t length. We can use "%d" also to print size_t variables, it may not always produce an error. The correct way to print size_t variables is use of "%zu", because compiler standard %zu is defined as a format specifier for this unsigned type. Following is the description of "%zu" format: z is a length modifier. u stands for an unsigned type. C Example to Print Value of size_t Variable In this example, we demonstrate a C program that correctly prints a ... Read More

exit(), abort() and assert() in C/C++

Tapas Kumar Ghosh
Updated on 04-Jun-2025 17:30:39

2K+ Views

In C and C++ programming, the exit(), abort(), and assert() functions are used for program termination and debugging. Each of these functions have different purpose and defined in different header files. In this article, we will learn these functions and their usage with the help of examples. The exit() Function In C/C++, exit() function is used to terminate the function call immediately without the executing further processes. This function is defined in  (in C) and / (in C++) header file and does not return any value. Syntax Following is the basic syntax of exit() function: void exit(int status_value); Here, ... Read More

C++ Program to Implement String Matching Using Vectors

Farhan Muhamed
Updated on 04-Jun-2025 16:25:31

638 Views

In C++, we can create vectors easily using the standard library. We are taking the main string and the string that will be searched as a vector, then searching it into the main string. When one match is found the function returns the address, and removes it from the main string. So in the next iteration, it starts from location 0 and searches again. For multiple occurrences, we are using loops and repeatedly searching for the match, and return the position. Input: Main String: "ABCcdABCcdABC" Substring to search: "cd" Output: Match found at Position = 1 Match found at ... Read More

C++ Program to Find the Minimum element of an Array using Binary Search approach

Ravi Ranjan
Updated on 04-Jun-2025 16:23:27

296 Views

The binary search works on the divide and conquer principle as it keeps dividing the array into half before searching. For applying the binary search algorithm, the given array should be sorted. Since the array is sorted we do not need to search the minimum element in the array. In this article, the given array has strictly decreasing elements in the left sub-array till it reaches the minimum element and the right sub-array has strictly increasing elements. For example: {40, 30, 20, 10, 25, 35}. In this example, the array is decreasing till it ... Read More

Advertisements