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 on Trending Technologies
Technical articles with clear explanations and examples
pthread_self() in C
The pthread_self() function in C is used to obtain the ID of the currently executing thread. This function provides a unique identifier for each running thread, allowing programs to distinguish between different threads during execution. Syntax pthread_t pthread_self(void); Parameters None − The function takes no parameters. Return Value Returns a pthread_t value representing the thread ID of the calling thread. Thread IDs are unique among all currently existing threads, but can be reused after a thread terminates. Example The following example demonstrates how pthread_self() works by ...
Read MoreSaving an Image from URL in PHP
There are several ways to save an image from a URL in PHP. Here are three common methods − Using file_get_contents() and file_put_contents() Using cURL Using the GD library Using file_get_contents() and file_put_contents() Using file_get_contents() and file_put_contents() is a straightforward method to save an image from a URL in PHP ? In this code snippet, file_get_contents() retrieves the contents of the image file from the specified URL. The image data is then stored in the $image variable. Next, file_put_contents() saves ...
Read Morepthread_equal() in C
The pthread_equal() function is used to check whether two threads are equal or not. This function returns 0 if the threads are different, or a non-zero value if the threads are equal. Syntax int pthread_equal(pthread_t th1, pthread_t th2); Parameters th1 − First thread identifier th2 − Second thread identifier Return Value Returns a non-zero value if threads are equal, otherwise returns 0. Note: To compile and run pthread programs, use: gcc -pthread filename.c -o output Example 1: Comparing Thread with Itself In this example, we ...
Read MoreRefresh a Page Using PHP
In PHP, you can refresh a page using the header() function to send HTTP headers to the browser. This is useful for creating auto-refreshing pages or redirecting users after form submissions. Using header() Function The header() function sends HTTP headers to the browser. To refresh a page, you use the "Refresh" header with a specified delay time. Syntax header(string $header, bool $replace = true, int $http_response_code = 0): void Parameters $header − The header string to send (e.g., "Refresh: 5") $replace − Whether to replace previous similar headers (default: true) $http_response_code ...
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 MorePHP Program to Find the Number Occurring Odd Number of Times
Finding a number that occurs an odd number of times in an array is a common programming problem. In PHP, this can be solved using different approaches like counting, hashing, or bitwise XOR operations. Problem Explanation Given an array where all numbers appear an even number of times except one, we need to find that single number which appears an odd number of times. For example, in the array [2, 3, 4, 3, 1, 4, 2, 1, 1], the number 1 appears 3 times (odd), while all other numbers appear an even number of times. Method ...
Read Morenextafter() and nexttoward() in C/C++
The nextafter() and nexttoward() functions in C are used to find the next representable floating-point value after a given number in a specified direction. These functions are part of the math.h library and are useful for precise floating-point arithmetic operations. Syntax double nextafter(double x, double y); float nextafterf(float x, float y); long double nextafterl(long double x, long double y); double nexttoward(double x, long double y); float nexttowardf(float x, long double y); long double nexttowardl(long double x, long double y); Parameters x − The starting value y − The direction value. The function ...
Read MorePHP Program to find the Closest Pair from Two Sorted Arrays
Given two sorted arrays and a number x, we need to find a pair (one element from each array) whose sum is closest to x. This is a classic two-pointer problem that can be solved efficiently. Problem Statement Find a pair from two sorted arrays such that the sum of the pair is closest to a given target value x. Input: ar1 = [1, 3, 5, 7, 9]; ar2 = [2, 4, 6, 8, 10]; x = 12; Output: The closest pair is [1, 10] because 1+10=11 which is closest to 12 ...
Read MoreInteresting Facts about C Programming
C programming language has several interesting and lesser-known features that can surprise even experienced programmers. Here are some fascinating facts about C that demonstrate its flexibility and unique behaviors. Fact 1: Switch Case Labels Inside If-Else Case labels in a switch statement can be placed inside if-else blocks due to the way switch works with jump labels − #include int main() { int x = 2, y = 2; switch(x) { case 1: ...
Read MorePHP program to Fetch Data from Localhost Server Database using XAMPP
To fetch data from a localhost server database using XAMPP, you need to set up a local web server environment and create a PHP script that connects to your MySQL database. This tutorial will guide you through the complete process. Prerequisites: Install XAMPP from https://www.apachefriends.org/download.html before proceeding. Setting Up XAMPP Server Step 1: Start the XAMPP Server Launch the XAMPP control panel Start the Apache and MySQL services by clicking "Start" next to each service Step 2: Access phpMyAdmin ...
Read More