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 2 of 597
Corrupt stack problem in C, C++ program
The corrupt stack problem is a critical runtime issue in C programming that occurs when the program's stack memory becomes compromised. This can lead to unpredictable program behavior, crashes, and security vulnerabilities. Understanding stack corruption is essential for writing robust C programs. What is a Stack in C? In C, the stack is a region of memory used for automatic storage of local variables, function parameters, and return addresses. It operates on a Last-In-First-Out (LIFO) principle, where the most recently allocated memory is freed first when functions return. What is Corrupt Stack Problem? Stack corruption occurs ...
Read MoreSignificance of Lambda Function in C/C++
Lambda Function − Lambda functions are anonymous inline functions that don't require any implementation outside the scope where they are defined. They provide a concise way to write small functions directly at the point of use. Lambda functions can also be stored in variables and treated as objects that can be called (called functors). When the compiler encounters a lambda function definition, it creates a custom object for that lambda. Note: Lambda functions are a C++11 feature and are NOT available in C. They are part of the C++ standard, not C. In C programming, you would use ...
Read MoreDifferent ways to declare variable as constant in C and C++
In C programming, constants are fixed values that cannot be changed during program execution. There are multiple ways to declare variables as constants, each with its own characteristics and use cases. Syntax const data_type variable_name = value; #define MACRO_NAME value enum { constant1, constant2, ... }; Method 1: Using const Keyword The const keyword is the most common way to create read-only variables. Once declared, attempting to modify the value results in a compilation error − #include int main() { const int value = 5; ...
Read MoreCount minimum bits to flip such that XOR of A and B equal to C in C++
We are given three binary sequences A, B and C of length N. Each sequence represents a binary number. We have to find the number of bit flips required in A and B such that XOR of A and B results in C. Syntax int flipCount(int A[], int B[], int C[], int n); First, let us understand the XOR operation truth table − X ...
Read MoreWriting C/C++ code efficiently in Competitive programming
In competitive programming, writing efficient C code is crucial for achieving better performance and rankings. Fast execution and optimal memory usage can make the difference between acceptance and time limit exceeded. Key Concepts Template − Code that works with different data types without rewriting Macro − Named code fragment that gets replaced during preprocessing Dynamic Arrays − Arrays that can resize during runtime Essential Optimization Techniques Fast Input/Output Methods Using scanf() and printf() instead of slower alternatives provides significant performance improvements ? #include int main() { ...
Read MoreWriting OS Independent Code in C/C++
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 Morembrtowc() function in C/C++ program
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 Moreputwchar() function in C/C++
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 MoreIseek() in C/C++ to read the alternate nth byte and write it in another file
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 MoreInteger literal in C/C++ (Prefixes and Suffixes)
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