Programming Articles

Page 1003 of 2547

Storage of integer and character values in C

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 1K+ Views

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

Convert C/C++ program to Preprocessor code

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 550 Views

Here we will see how to generate the preprocessed or preprocessor code from the source code of a C or C++ program. To see the preprocessed code using gcc compiler, we have to use the '-E' option with the gcc. The preprocessor includes all of the # directives in the code, and also expands the MACRO function. Syntax gcc -E program.c Example Let's create a simple C program with macro definitions and see how the preprocessor expands them − #include #define PI 3.1415 #define SQUARE(x) ((x) * (x)) int ...

Read More

How to Remove Portion of a String after a Certain Character in PHP

Pradeep Kumar
Pradeep Kumar
Updated on 15-Mar-2026 4K+ Views

In PHP, removing a portion of a string after a certain character is a common string manipulation task. There are several effective methods to accomplish this, each with its own advantages depending on your specific use case. Using strpos() and substr() This method finds the position of a character and extracts everything before it − Hello The strpos() function finds the position of the target character. We use substr() to extract the substring from position 0 to the character's position, effectively removing everything after it. Using explode() and Taking ...

Read More

How does a C program executes?

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 6K+ Views

Here we will see how C programs are executed in a system. This is basically the compilation process of a C program from source code to executable machine code. The following diagram shows how a C source code file gets converted into an executable program − C Source Code (.c file) Preprocessor (.i file) ...

Read More

How to Remove Extension from String in PHP

Pradeep Kumar
Pradeep Kumar
Updated on 15-Mar-2026 2K+ Views

In PHP, removing the file extension from a string is a common task when working with filenames. There are several effective methods to accomplish this, each with its own advantages depending on your specific needs. Using the pathinfo() Function The pathinfo() function is the most straightforward and reliable method to remove file extensions ? exampleFile The pathinfo() function with PATHINFO_FILENAME constant returns the filename without the extension. This method is safe and handles edge cases well. Using substr() and strrpos() Functions This method finds the last dot position ...

Read More

How to Recursively Delete a Directory and its Entire Contents (files + sub dirs) in PHP

Pradeep Kumar
Pradeep Kumar
Updated on 15-Mar-2026 4K+ Views

In PHP, recursively deleting a directory and its entire contents requires careful handling of files and subdirectories. PHP provides several approaches to accomplish this task using built-in functions and classes. Method 1: Using rmdir() and unlink() Functions This method uses scandir() to list directory contents, then recursively processes each item − This approach first checks if the path is a directory, scans its contents, and recursively deletes subdirectories while unlinking files directly. Method 2: Using glob() Function The glob() function provides a cleaner way to retrieve directory contents using pattern matching ...

Read More

Uninitialized primitive data types in C/C++

Nishtha Thakur
Nishtha Thakur
Updated on 15-Mar-2026 399 Views

In C programming, uninitialized primitive data types contain unpredictable values called "garbage values". The C standard does not guarantee that these variables will be initialized to zero or any specific value. The actual values depend on what was previously stored in those memory locations. Syntax data_type variable_name; // Uninitialized variable data_type variable_name = initial_value; // Initialized variable Example: Uninitialized Variables Let's examine what happens when we declare variables without initializing them − #include int main() { char a; float b; ...

Read More

How to Read if a Checkbox is Checked in PHP

Pradeep Kumar
Pradeep Kumar
Updated on 15-Mar-2026 13K+ Views

In PHP, you can check if a checkbox is checked by using several methods depending on how your form is structured. When a checkbox is checked, its value is included in the form submission data; when unchecked, it's not sent at all. Using isset() Function The most reliable method is using isset() to check if the checkbox value exists in the submitted data − Subscribe to newsletter Using empty() Function You can also use empty() for a ...

Read More

How to modify a const variable in C?

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 6K+ Views

In C, const variables are designed to be immutable after initialization. However, there are ways to modify their values using pointers, though this practice leads to undefined behavior and should be avoided in production code. Syntax const data_type variable_name = value; int *ptr = (int*)&const_variable; // Cast away const *ptr = new_value; // Modify through pointer Example 1: Attempting Direct Modification (Compile Error) Direct assignment to a const variable results in a compilation error − #include int main() { const int x = 10; ...

Read More

Macros vs Functions in C

Nishtha Thakur
Nishtha Thakur
Updated on 15-Mar-2026 3K+ Views

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 More
Showing 10021–10030 of 25,466 articles
Advertisements