Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
C++ Articles
Page 3 of 597
INT_MAX and INT_MIN in C/C++ and Applications
In C programming, INT_MAX and INT_MIN are predefined macros that represent the maximum and minimum values that can be stored in an int variable. These macros are defined in the header file and are essential for boundary checking and initialization in various algorithms. Syntax INT_MAX /* Maximum value for int */ INT_MIN /* Minimum value for int */ Basic Example Let's see how to use INT_MAX and INT_MIN in a simple program − #include #include int main() { ...
Read MoreFind the Longest Substring Containing Vowels in Even Counts in C++
The problem of finding the longest substring with vowels appearing an even number of times can be solved efficiently using bit manipulation and prefix sums. We need to track the parity (odd/even count) of each vowel ('a', 'e', 'i', 'o', 'u') as we traverse the string. Syntax int findLongestSubstring(char* s); Algorithm Steps The approach uses a bitmask to represent the parity state of vowels − Use a 5-bit mask where each bit represents parity of vowels a, e, i, o, u Store the first occurrence of each mask state When a mask ...
Read MoreCreating a C/C++ Code Formatting tool with help of Clang tools
In this tutorial, we will be discussing how to create a C/C++ code formatting tool using Python and clang-format. This tool automatically formats all C/C++ source files in a project directory according to specified coding standards. Installation Requirements: sudo apt install python3 sudo apt install clang-format How It Works The tool works by recursively scanning directories for C/C++ files and applying clang-format to each file. It uses Python's os.walk() to traverse directories and identifies source files by their extensions. Example: Python Code Formatter Script Create a Python file named format_code.py in your project ...
Read MoreCreate Directory or Folder with C/C++ Program
Creating a folder or directory on your computer is an important task in programming. A directory is like a container that helps store and organize files. In C, you often need to create directories to store data, logs, or configuration files. Creating directories makes file management easier. For example, if your program needs to store logs, it should check if a "logs" folder exists. If not, it can create the folder automatically, so you don't have to do it manually. In this article, we'll show you how to create a directory in C using the mkdir() function. ...
Read MoreCore Dump (Segmentation fault) in C/C++
Core dump (segmentation fault) is a runtime error that occurs when a program tries to access memory that it isn't allowed to access or tries to access memory in a way that isn't allowed. This results in the operating system terminating the program abnormally to prevent potential system damage. A segmentation fault typically happens when code tries to write to read-only memory, accesses corrupt memory locations, or violates memory access permissions. Syntax /* Common scenarios that cause segmentation faults */ char *ptr = NULL; *ptr = 'A'; ...
Read MoreConverting Strings to Numbers in C/C++
In C programming, converting strings to numbers is a common task that can be accomplished using several standard library functions. C provides multiple approaches to convert string representations of numbers into their corresponding numeric values. Syntax int atoi(const char *str); long atol(const char *str); double atof(const char *str); long strtol(const char *str, char **endptr, int base); double strtod(const char *str, char **endptr); Method 1: Using atoi() for Integer Conversion The atoi() function converts a string to an integer value − #include #include int main() { ...
Read MoreConvert a String to Integer Array in C/C++
In C, converting a comma-separated string to an integer array involves parsing the string character by character and extracting numeric values. This process requires traversing the string, identifying delimiters (commas), and converting individual number substrings to integers. Syntax // Function to convert string to integer array void convertStringToArray(char str[], int arr[], int *size); Example: Using Character-by-Character Parsing This approach traverses the string and builds integers by accumulating digits until a comma is encountered − #include #include void convertStringToArray(char str[], int arr[], int *size) { int i = 0, j = 0, num = 0; int len = strlen(str); for (i = 0; i = '0' && str[i]
Read MoreHow to add "graphics.h" C/C++ library to gcc compiler in Linux
In C programming, the graphics.h library provides functions for creating graphics programs. However, this library is not part of the standard C library and requires special installation on Linux systems. Here we'll show how to install and use the graphics library with gcc compiler. Installation Requirements Before using graphics.h, you need to install the required packages and compile the libgraph library on your Linux system. First, install the build essentials and required dependencies − sudo apt-get install build-essential sudo apt-get install libsdl-image1.2 libsdl-image1.2-dev guile-2.0 guile-2.0-dev libsdl1.2debian libart-2.0-dev libaudiofile-dev libesd0-dev libdirectfb-dev libdirectfb-extra libfreetype6-dev ...
Read MoreHow arrays are passed to functions in C/C++
In this tutorial, we will be discussing how arrays are passed to functions in C. Understanding this concept is crucial for proper array handling in C programming. In C, arrays are never passed by value to functions. Instead, when you pass an array to a function, what actually gets passed is a pointer to the first element of the array. This is called "array decay" − the array name decays into a pointer. Syntax // Method 1: Array notation void function_name(data_type array_name[]); // Method 2: Pointer notation void function_name(data_type *array_name); // Method ...
Read MorePrint 2D matrix in different lines and without curly braces in C/C++
Here, we will see how to print a 2D matrix in C programming language without using curly braces. This technique uses a clever approach to eliminate the need for braces in nested loops. Curly braces are separators in C that define separate code blocks in the program. Without curly braces, defining scopes is difficult, but we can use a shorthand technique to achieve the same result for simple operations. Syntax for (int i = 0; i < rows; i++) for (int j = 0; j < cols; j++) ...
Read More