C Articles

Page 79 of 96

Designated Initializers in C

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

In C90 standard we have to initialize the arrays in the fixed order, like initialize index at position 0, 1, 2 and so on. From C99 standard, they have introduced designated initializing feature in C. Here we can initialize elements in random order. Initialization can be done using the array index or structure members. This extension is not implemented in GNU C++. Syntax // Array designated initialization type array[size] = {[index] = value, [index] = value, ...}; // Range designated initialization type array[size] = {[first ... last] = value}; // Structure designated initialization struct name ...

Read More

Name Mangling and extern "C" in C++

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

In C++, function overloading allows multiple functions with the same name but different parameter types or numbers. However, this creates a problem: how does the compiler distinguish between these functions in the object code? The solution is a technique called name mangling. Syntax extern "C" { // C function declarations } What is Name Mangling? Name mangling is a technique where the compiler modifies function names by adding information about parameters to create unique identifiers. C++ has no standardized name mangling scheme, so different compilers use different approaches. Example: ...

Read More

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 258 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 253 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 975 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 889 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 644 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
Showing 781–790 of 953 articles
« Prev 1 77 78 79 80 81 96 Next »
Advertisements