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
Programming Articles
Page 921 of 2547
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 MoreC program to implement CHECKSUM
In computing, a checksum is a small-sized data value computed from a larger data set using an algorithm, with the intention that any changes made to the larger data set will result in a different checksum. Checksums are commonly used to verify the integrity of data during transmission or storage. Syntax unsigned int checksum(char *data); // Returns computed checksum value for given data Why Use CHECKSUM? There are several reasons why checksums are used − Error detection − Detect errors that occur during data transmission or storage Data integrity − Ensure data ...
Read Morefopen() for existing file in write mode in C
The fopen() function in C is used to open files for various operations. When opening an existing file in write mode, it's important to understand how different modes affect the file's content. Syntax FILE *fopen(const char *filename, const char *mode); fopen() for an Existing File in Write Mode When using fopen() with write mode on an existing file − 'w' mode: Creates a new file if it doesn't exist, or truncates (empties) an existing file before writing 'w+' mode: Same as 'w' but allows both reading and writing 'a' mode: Appends new ...
Read MoreC Program to Redeclaration of global variable
In C programming, variable redeclaration refers to declaring a variable more than once in the same scope. The behavior of redeclaration varies between global and local variables, and differs between C and C++. Understanding these differences is crucial for avoiding compilation errors. Syntax // Global variable redeclaration int var; int var; // Allowed in C without initialization // Local variable redeclaration int main() { int var; int var; // Not allowed in C } Global Variable Redeclaration Without Initialization C allows ...
Read MoreC program to demonstrate usage of variable-length arrays
Variable-length arrays (VLAs) in C allow you to create arrays whose size is determined at runtime rather than compile time. This feature was introduced in C99 and provides dynamic array allocation on the stack. In this example, we'll demonstrate a library system that uses VLAs to manage books on shelves with three operations: adding books, querying book pages, and counting books per shelf. Syntax data_type array_name[variable_size]; // Where variable_size is determined at runtime Library Management System The system supports three commands − Command 1: Insert a book with y pages at shelf ...
Read MoreC program to find out the maximum value of AND, OR, and XOR operations that are less than a given value
Suppose we are given two integers k and n. Our task is to perform three operations; bitwise AND, bitwise OR, and bitwise XOR between all pairs of numbers up to range n. We return the maximum value of all three operations between any two pairs of numbers that is less than the given value k. So, if the input is like n = 5, k = 5, then the output will be 4 3 4. The greatest value of AND, OR, and XOR operations between all pairs of numbers that are less than 5 are 4, 3, and ...
Read MoreC program to sort triangles based on area
Suppose we have an array of different triangles where triangles[i] = [ai, bi, ci] these are the sides of ith triangle. We shall have to sort the triangles based on their area. The area of a triangle using sides is calculated with Heron's formula: square root of p*(p-a)*(p-b)*(p-c) where p = (a+b+c)/2. So, if the input is like (7, 24, 25), (5, 12, 13), (3, 4, 5), then the output will be (3, 4, 5), (5, 12, 13), (7, 24, 25) Syntax struct Triangle { int a, b, c; }; int ...
Read MoreC program to find sum, max and min with Variadic functions
Variadic functions in C allow you to create functions that can accept a variable number of arguments. This is useful when you need functions like sum(), max(), and min() that can work with different numbers of input values. To implement variadic functions, we use the ellipsis (...) notation and include the header file. Syntax return_type function_name(fixed_parameter, ...); The key macros for handling variable arguments are − va_list: Stores information about variable arguments va_start: Initializes the va_list to start accessing arguments va_arg: Retrieves the next argument of specified type va_end: Cleans up the ...
Read MoreC program to find permutations of given strings
In C, generating permutations of strings means finding all possible arrangements of a given array of strings. We can use the next permutation algorithm to systematically generate all permutations in lexicographical order. Syntax int next_permutation(int n, char **strings); Algorithm The next permutation algorithm works by − Finding the rightmost element that is smaller than its next element Finding the smallest element on the right side that is larger than the found element Swapping these two elements Reversing the sequence after the original smaller element Example Let us see the ...
Read MoreC program to find frequency of each digit in a string
In C, finding the frequency of each digit in a string involves scanning through the string character by character and counting occurrences of digits (0-9). We use an array to store the frequency count for each digit. Syntax int freq[10] = {0}; // Array to store frequency of digits 0-9 if (str[i] >= '0' && str[i] = '0' && s[i] 0) { printf("(Number %d, Freq %d)", i, freq[i]); } } } ...
Read More