C++ Articles

Page 3 of 597

Writing OS Independent Code in C/C++

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 551 Views

Writing OS-independent code in C allows programs to run across different operating systems without modification. This is achieved using preprocessor macros that detect the target platform at compile time. Syntax #ifdef MACRO_NAME // OS-specific code #elif defined(ANOTHER_MACRO) // Alternative OS code #else // Default code #endif Common OS Detection Macros GCC and other C compilers define platform-specific macros automatically − _WIN32 − Defined for 32-bit and 64-bit Windows _WIN64 − Defined only for 64-bit Windows __unix__ − Defined for Unix-like ...

Read More

mbrtowc() function in C/C++ program

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 301 Views

The mbrtowc() function is used to convert a multibyte character sequence to a wide character. This function is part of the C standard library and is defined in the header file. It provides a safe way to convert multibyte characters (like UTF-8) to wide character representation. Syntax size_t mbrtowc(wchar_t* pwc, const char* s, size_t n, mbstate_t* ps); Parameters The function accepts the following parameters − pwc − Pointer to the location where the resulting wide character will be stored s − Pointer to the multibyte character string to be converted n ...

Read More

putwchar() function in C/C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 166 Views

The putwchar() function in C is used to write a wide character to the standard output (stdout). It is the wide character equivalent of the putchar() function and is defined in the header file. Syntax wint_t putwchar(wchar_t wc); Parameters wc − The wide character to be written to stdout Return Value On success: Returns the wide character that was written On failure: Returns WEOF and sets an error indicator Example 1: Writing Single Wide Character This example demonstrates writing a single wide character to stdout ...

Read More

Iseek() in C/C++ to read the alternate nth byte and write it in another file

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 821 Views

The lseek() function in C is used to change the file offset (position) of the file descriptor. It allows us to read data from specific positions in a file by moving the file pointer. In this tutorial, we'll demonstrate how to read alternate nth bytes from one file and write them to another file. Note: This program requires file I/O operations with system calls that may not work in all online compilers. Create "start.txt" with sample content before running. Syntax off_t lseek(int fd, off_t offset, int whence); Parameters fd − ...

Read More

Integer literal in C/C++ (Prefixes and Suffixes)

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 2K+ Views

Integer literals in C are numeric values written directly in the source code to represent integer constants. They can be modified using prefixes to specify the base (decimal, octal, hexadecimal, binary) and suffixes to specify the data type (int, long, unsigned, etc.). Integer literals are of two types − Prefixes − Indicate the number base. For example, 0x10 represents hexadecimal value 16. Suffixes − Specify the data type. For example, 123LL represents a long long integer. Syntax // Prefixes decimal_literal (no prefix) 0octal_literal (prefix ...

Read More

INT_MAX and INT_MIN in C/C++ and Applications

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 3K+ Views

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 More

Find the Longest Substring Containing Vowels in Even Counts in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 415 Views

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 More

Creating a C/C++ Code Formatting tool with help of Clang tools

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 278 Views

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 More

Create Directory or Folder with C/C++ Program

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 4K+ Views

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 More

Core Dump (Segmentation fault) in C/C++

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 5K+ Views

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 More
Showing 21–30 of 5,962 articles
« Prev 1 2 3 4 5 597 Next »
Advertisements