Programming Articles

Page 996 of 2547

What does it mean when a numeric constant in C/C++ is prefixed with a 0?

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

When a numeric constant in C is prefixed with a 0, it indicates that the number is an octal number (base 8). Octal literals must start with 0 to distinguish them from decimal numbers. For example, the octal number 25 is written as 025 in C. Syntax 0octal_digits Where octal_digits are valid octal digits (0-7). Example: Octal Number Conversion The following program demonstrates how octal literals are converted to decimal values − #include int main() { int a = 025; /* Octal ...

Read More

wprintf() and wscanf in C Library

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

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 More

Program for Christmas Tree in C

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

In C programming, creating a Christmas tree pattern involves printing pyramids of various sizes stacked one beneath another. This creates a festive tree-like structure with decorative characters that can simulate twinkling lights through randomization. Syntax void tree_triangle(int start, int end, int total_height); void display_tree(int height); void display_log(int height); Example: Static Christmas Tree Let's start with a basic Christmas tree that displays once − #include #include #include void display_random_leaf() { char type_of_leaves[5] = { '.', '*', '+', 'o', 'O' }; int ...

Read More

Why strict aliasing is required in C?

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

Strict aliasing is a critical concept in C that helps prevent undefined behavior when accessing the same memory location through pointers of different types. Understanding why it's required helps write safer and more predictable C code. What is Strict Aliasing? Strict aliasing is a rule that states an object can only be accessed through pointers of compatible types. When this rule is violated, the behavior becomes undefined, leading to unpredictable results. Example: Strict Aliasing Violation Here's an example demonstrating what happens when strict aliasing rules are violated − #include int temp = ...

Read More

Linear search using Multi-threading in C

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 987 Views

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 More

Print numbers in sequence using thread synchronization

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

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 More

What is data type of FILE in C?

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 3K+ Views

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 More

Hygienic Macros in C

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

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 More

Incompatibilities between C and C++

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

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 More

Sort Array of Objects by Object Fields in PHP

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

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 More
Showing 9951–9960 of 25,466 articles
« Prev 1 994 995 996 997 998 2547 Next »
Advertisements