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
Server Side Programming Articles
Page 985 of 2109
Macros vs Functions in C
Macros and functions are two different mechanisms in C for code reuse, but they work fundamentally differently. Macros are preprocessed before compilation, meaning they are textually replaced in the code. Functions are compiled as separate code blocks that are called during execution. Syntax #define MACRO_NAME(parameters) replacement_text return_type function_name(parameters) { // function body return value; } Example: Macro vs Function Problem This example demonstrates a common issue where macros and functions produce different results due to the way macros expand − #include ...
Read MoreHow to Read any Request Header in PHP
PHP provides several methods to read HTTP request headers, which contain important information about the client's request such as user agent, content type, and authentication details. Understanding how to access these headers is essential for web development tasks like content negotiation, security checks, and API development. Using $_SERVER Superglobal The most common method is using the $_SERVER superglobal array. Header names are prefixed with "HTTP_", converted to uppercase, and hyphens are replaced with underscores − Using getallheaders() Function The getallheaders() function returns all request headers as an associative array. This method preserves ...
Read MoreConvert C/C++ code to assembly language
Assembly language is a low-level programming language that provides a human-readable representation of machine code. The GNU Compiler Collection (GCC) allows us to convert C/C++ source code into assembly language for analysis and optimization purposes. Syntax gcc -S source_file.c gcc -S source_file.cpp Note: To use gcc, you need to install it on your system. On Ubuntu/Debian: sudo apt install gcc, on Windows: install MinGW or use WSL. Parameters -S − Generate assembly code and stop before assembling source_file − The C/C++ source file to convert Example: Simple C ...
Read MoreHow to Log Errors and Warnings into a File in PHP
In PHP, logging errors and warnings to files is essential for debugging and monitoring applications. PHP provides built-in functions like error_log() and ini_set() to capture and store error messages for later analysis. Method 1 − Using error_log() Function The error_log() function sends error messages to the server's error log or a specified file ? Syntax error_log(string $message, int $messageType = 0, string $destination = '', string $extraHeaders = ''); Parameters $message: The error message or data to be logged (string) $messageType: (Optional) The ...
Read MoreHow does free() know the size of memory to be deallocated?
The free() function is used to deallocate memory that was allocated using malloc(), calloc(), or realloc(). The syntax of free() is simple − it only takes a pointer as an argument and deallocates the memory. Syntax void free(void *ptr); The interesting question is: how does free() know the size of the memory block to deallocate when it only receives a pointer? How free() Determines Memory Block Size When you allocate memory using dynamic memory allocation functions, the memory management system stores metadata about each allocated block. This metadata typically includes the size of ...
Read MoreHow to Pass PHP Variables by Reference
In PHP, you can pass variables by reference instead of by value using the ampersand (&) symbol. This allows you to modify the original variable within a function or method. There are primarily two ways to pass PHP variables by reference: Using the ampersand in the function/method declaration Using the ampersand when passing the variable to a function/method Using the Ampersand in the Function/Method Declaration To pass variables by reference using the ampersand in the function/method declaration, you need to include the ampersand symbol before the parameter ...
Read MoreHow to get the Last n Characters of a PHP String
In PHP, you can extract the last n characters of a string using the substr() function with a negative start position. This approach counts from the end of the string backwards. Using substr() Function The substr() function extracts a portion of a string based on the starting position and optional length. To get the last n characters, use a negative starting position. Syntax substr(string $string, int $start, ?int $length = null): string|false Parameters: $string − The input string from which to extract characters $start ...
Read MoreCompound Literals in C
In C, compound literals are a feature introduced in the C99 standard that allows you to create unnamed objects with automatic storage duration. This feature enables you to initialize arrays, structures, and unions directly in expressions without declaring a separate variable. Syntax (type_name) { initializer_list } Example 1: Compound Literal with Structure Here's how to use compound literals to create an unnamed structure object − #include struct point { int x; int y; }; void display_point(struct point pt) { ...
Read MoreHow To Get Multiple Selected Values Of Select Box In PHP
In PHP, when you have a multiple select box (dropdown) that allows users to select more than one option, you need to handle the selected values as an array. This is accomplished by setting the name attribute with square brackets and using PHP's superglobal arrays to retrieve the values. Method 1: Using $_POST with Array Name Attribute The most common approach is to set the name attribute of the select element as an array using square brackets. This tells PHP to treat the submitted values as an array − HTML Form Structure ...
Read MoreMultiline macros in C
In C programming, multiline macros allow you to define complex operations that span multiple lines. Unlike single-line macros, each line in a multiline macro must be terminated with a backslash '' character to indicate line continuation. When using multiline macros, it's recommended to enclose the entire macro definition in parentheses to avoid potential syntax errors. Syntax #define MACRO_NAME(parameters) ({\ statement1;\ statement2;\ statement3;\ }) Example 1: Basic Multiline Macro Here's an example demonstrating how to create and use a multiline macro for printing ...
Read More