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
Articles by Anvi Jain
Page 5 of 43
wprintf() and wscanf in C Library
In C programming, wprintf() and wscanf() are wide character equivalents of printf() and scanf() functions. These functions handle wide characters and wide strings, making them essential for internationalization and Unicode text processing. Both functions are declared in the wchar.h header file. wprintf() Syntax int wprintf(const wchar_t* format, ...); Parameters format − A pointer to a null-terminated wide string containing format specifiers starting with % ... − Additional arguments corresponding to the format specifiers Return Value Returns the number of wide characters printed on success, or a negative value on failure. ...
Read MoreLinear search using Multi-threading in C
Linear search using multi-threading in C involves dividing an array into multiple segments and assigning each segment to a separate thread for searching. This parallel approach can improve search performance on multi-core systems by utilizing multiple CPU cores simultaneously. Syntax pthread_create(&thread_id, NULL, search_function, thread_data); pthread_join(thread_id, NULL); Example To compile and run this program, you need to link with the pthread library using: gcc filename.c -lpthread Here's how to implement multi-threaded linear search where each thread searches a specific portion of the array − #include #include #include ...
Read MoreDifference between fork() and exec() in C
In C, fork() and exec() are fundamental system calls for process management. The fork() function creates a new process by duplicating the calling process, while exec() replaces the current process image with a new program. Syntax #include pid_t fork(void); int exec(const char *path, char *const argv[]); Key Differences Aspect fork() exec() Purpose Creates new process (duplicate) Replaces current process image Process Count Increases by one Remains same Memory Image Copies parent's memory Loads new program Return Value Child PID to parent, 0 to ...
Read Morepthread_cancel() in C
The pthread_cancel() function is used to send a cancellation request to a specific thread identified by its thread ID. This function allows one thread to request the termination of another thread in a controlled manner. Note: To compile and run pthread programs, use: gcc -pthread filename.c -o output Syntax int pthread_cancel(pthread_t thread); Parameters thread − The thread ID of the thread to be cancelled Return Value Returns 0 on success Returns an error number on failure Example: Thread Cancellation This example demonstrates how ...
Read MoreCheck input character is alphabet, digit or special character in C
In this section, we will see how to check whether a given character is a number, alphabet, or special character in C. We can classify characters by checking their ASCII values against specific ranges. The alphabets are from A – Z and a – z, numbers are from 0 – 9, and all other characters are considered special characters. Syntax if((ch >= 'A' && ch = 'a' && ch = '0' && ch = 'A' && ch = 'a' && ch = '0' && ch
Read MoreC function argument and return values
In C programming, functions can be categorized based on two criteria: whether they accept arguments (parameters) and whether they return a value. This gives us four distinct types of functions that cover all possible combinations. Syntax return_type function_name(parameter_list) { // Function body return value; // Optional, depends on return_type } Types of Functions Function with no arguments and no return value − Takes no input and returns nothing (void) Function with no arguments but returns a value − Takes no input but returns a value ...
Read MoreModulus of two float or double numbers using C
In C, to find the modulus (remainder) of two floating-point or double numbers, we use the remainder() function from the math library. Unlike the % operator which only works with integers, remainder() handles floating-point arithmetic. Syntax double remainder(double x, double y); float remainderf(float x, float y); long double remainderl(long double x, long double y); Parameters x − The numerator (dividend) y − The denominator (divisor) Return Value Returns the floating-point remainder of x/y. The remainder is calculated as: remainder(x, y) = x - rquote * y ...
Read MoreHow to measure time taken by a function in C?
Here we will see how to calculate the time taken by a process or function in C. For this problem, we will use the clock() function. The clock() function is present in the time.h header file. To get the elapsed time, we can get the time using clock() at the beginning, and at the end of the tasks, then subtract the values to get the differences. After that, we will divide the difference by CLOCKS_PER_SEC (Number of clock ticks per second) to get the processor time. Syntax clock_t clock(void); Example Here's a complete ...
Read MoreAssigning multiple characters in an int in C language
The character type data is stored by its ASCII value internally in C. If we want to print a single character as integer, we will get the ASCII value. But when we are trying to print more than one character using a single quote, then it will print some strange output. Syntax int variable = 'character'; int variable = 'multiple_chars'; // Non-standard behavior Example Please check the following program to get the idea − #include int main() { printf("%d", 'A'); printf("%d", ...
Read MoreStorage of integer and character values in C
We have used the integer and character variables many times in our program. Here we will see how they are stored in the memory. In C the character values are also stored as integers. When we assign a value larger than the character range to a char variable, overflow occurs and only the lower 8 bits are stored. Syntax char variable_name = value; int variable_name = value; Example: Character Overflow Behavior In the following code, we shall put 270 into a character type data. The binary equivalent of 270 is 100001110, but char ...
Read More