Nishtha Thakur

Nishtha Thakur

398 Articles Published

Articles by Nishtha Thakur

Page 2 of 40

Style select options with CSS

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

The CSS select element can be styled to enhance its appearance and user experience. You can modify properties like width, padding, borders, background colors, and more to customize the dropdown menu. Syntax select { property: value; } Example: Styling Select Element The following example demonstrates how to style a select dropdown with custom padding, borders, and background color − select { width: 100%; padding: ...

Read More

How to create a modal popup using JavaScript and CSS?

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

Creating a modal popup means adding a dialog box, which generates on click of a button and closes when the user clicks anywhere outside of the popup or on the close button. × Modal Header This is the modal content. Click outside or on × ...

Read More

Why do we check for a NULL pointer before deleting in C/C++?

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

In C programming, checking for a NULL pointer before calling free() is often seen in code, but it's technically unnecessary. The free() function is designed to safely handle NULL pointers by doing nothing when passed a NULL value. Syntax void free(void *ptr); Why NULL Check is Unnecessary According to the C standard, free(NULL) is guaranteed to be a no-op (no operation). This means the following code is redundant − #include #include int main() { int *ptr = NULL; ...

Read More

The best way to check if a file exists using standard C/C++

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

In C programming, checking if a file exists is a common task that can be accomplished by attempting to open the file for reading. If the file opens successfully, it exists; otherwise, it doesn't exist. Syntax FILE *fopen(const char *filename, const char *mode); Method 1: Using fopen() Function The most straightforward approach is to use fopen() to attempt opening the file in read mode − #include int main() { FILE *file; /* Try to open file for ...

Read More

C program that won't compile in C++

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

C++ is largely based on C, but it enforces stricter type checking and syntax rules. While most C programs compile in C++, some valid C code will not compile in C++ due to these stricter rules. Understanding these differences helps in writing portable code. Syntax There is no specific syntax for this concept, but rather a collection of C language features that C++ treats differently or rejects entirely. Example 1: Function Declaration Requirements In C, functions can be called before declaration (with implicit declaration), but C++ requires explicit declaration − #include int ...

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

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

Print numbers in sequence using thread synchronization

Nishtha Thakur
Nishtha Thakur
Updated on 15-Mar-2026 872 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

Hygienic Macros in C

Nishtha Thakur
Nishtha Thakur
Updated on 15-Mar-2026 634 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

pthread_self() in C

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

The pthread_self() function in C is used to obtain the ID of the currently executing thread. This function provides a unique identifier for each running thread, allowing programs to distinguish between different threads during execution. Syntax pthread_t pthread_self(void); Parameters None − The function takes no parameters. Return Value Returns a pthread_t value representing the thread ID of the calling thread. Thread IDs are unique among all currently existing threads, but can be reused after a thread terminates. Example The following example demonstrates how pthread_self() works by ...

Read More
Showing 11–20 of 398 articles
« Prev 1 2 3 4 5 40 Next »
Advertisements