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
Print numbers in sequence using thread synchronization
Thread synchronization allows multiple threads to coordinate and execute in a specific order. In this example, we create n threads where each thread prints its number in sequence − thread 1 prints 1, thread 2 prints 2, and so on. We use mutex locks and condition variables to ensure proper synchronization. Note: To compile and run this program, you need to link with the pthread library: gcc program.c -lpthread -o program Syntax pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t condition_variable; pthread_mutex_lock(&mutex); pthread_cond_wait(&condition_variable, &mutex); pthread_cond_signal(&condition_variable); pthread_mutex_unlock(&mutex); Example: Sequential Number Printing with Threads This program ...
Read MoreSetting Up LEMP Linux, Nginx, MySQL/MariaDB, PHP) and PhpMyAdmin on Ubuntu 15.04 Server
LEMP stack is a powerful combination of open source technologies used for web development and hosting. LEMP comprises Linux (the operating system), Nginx (pronounced "engine-x", a web server), MySQL/MariaDB (database management), and PHP (server-side scripting language). Note: Ubuntu 15.04 has reached end-of-life. This guide is for educational purposes. Consider using a current Ubuntu LTS version for production environments. Prerequisites Before starting the installation, ensure you have − Ubuntu 15.04 server with root or sudo access Internet connection for package downloads Basic command line knowledge Manual Installation Method Step 1: Update ...
Read MoreWhat is data type of FILE in C?
In C, FILE is a special data type used to handle file operations. FILE is what we call an "opaque data type" − its internal implementation is hidden from the programmer and is system-specific. When we work with files, we use pointers of type FILE to access and manipulate file data. Syntax FILE *file_pointer; What Makes FILE an Opaque Data Type? The FILE structure contains internal fields that manage file operations like buffering, positioning, and error states. The actual definition varies between different operating systems and C library implementations. FILE Structure Definition (System-Specific) ...
Read MoreSetting Up LAMP (Linux, Apache, MariaDB and PHP) on Fedora 24 Server
Follow these instructions to install LAMP (Linux, Apache, MariaDB, and PHP) on a Fedora 24 server. LAMP stack provides a complete web development environment with Linux as the operating system, Apache as the web server, MariaDB as the database, and PHP for server-side scripting. Prerequisites: Ensure you have a fresh Fedora 24 server installation with root or sudo access and an active internet connection. Step 1: Update System First, update your system packages to ensure you have the latest versions ? sudo dnf update -y Step 2: Install Apache Web Server ...
Read MoreHygienic Macros in C
Here we will see the Hygienic Macros in C. We know the usage of macros in C. But sometimes, macros do not return the desired results because of accidental capture of identifiers, where macro variables interfere with variables in the calling code. Syntax #define MACRO_NAME(params) do { /* avoid variable name conflicts */ } while(0) Problem: Non-Hygienic Macro If we see the following code, we can see that it is not working properly because the macro uses variable name 'a' which conflicts with the program's variable − #include #define INCREMENT(i) do ...
Read MoreHow to display logged-in user information in PHP?
In this article, we will learn how to display logged-in user information using PHP sessions. When building web applications with authentication, displaying user information on various pages provides a personalized experience for users. We can implement user authentication and display logged-in user information using PHP sessions along with HTML forms. Let's explore this with practical examples. Basic User Authentication System This example demonstrates a complete login system with user authentication and information display − Filename: login.php Login Page Login ...
Read MoreIncompatibilities between C and C++
Here we will see some incompatibilities between C and C++. Some C codes that can be compiled using C compiler, but does not compile in C++ compiler and returns errors. Syntax // C allows various syntaxes that C++ rejects // Old-style function declarations, implicit int, multiple declarations, etc. Example 1: Old-Style Function Declarations C allows defining functions with parameter types specified after the parameter list − #include void my_function(x, y) int x; int y; { printf("x = %d, y = %d", x, y); } ...
Read MoreSort Array of Objects by Object Fields in PHP
In PHP, you can sort an array of objects by their properties using several built-in functions. Each approach offers different advantages depending on your specific requirements and coding style preferences. Using usort() Function with a Custom Comparison Function The usort() function provides the most flexible approach for sorting objects by custom logic ? Bob - 25 Alice - 30 Charlie - 35 Using Anonymous Functions You can also use anonymous functions for more concise code ? Mouse - $25.5 Keyboard - $75 Laptop ...
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 MoreSort a Multidimensional Array by Date Element in PHP
In PHP, you can sort a multidimensional array by a specific element, such as a date, using various approaches. Let's explore three different methods ? Using array_multisort() The array_multisort() function sorts multiple arrays or multidimensional arrays based on one or more columns ? Array ( [0] => Array ( [date] => 2023-05-15 [name] => Alice ...
Read More