Smita Kapse

Smita Kapse

388 Articles Published

Articles by Smita Kapse

Page 5 of 39

pthread_equal() in C

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

The pthread_equal() function is used to check whether two threads are equal or not. This function returns 0 if the threads are different, or a non-zero value if the threads are equal. Syntax int pthread_equal(pthread_t th1, pthread_t th2); Parameters th1 − First thread identifier th2 − Second thread identifier Return Value Returns a non-zero value if threads are equal, otherwise returns 0. Note: To compile and run pthread programs, use: gcc -pthread filename.c -o output Example 1: Comparing Thread with Itself In this example, we ...

Read More

Interesting Facts about C Programming

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

C programming language has several interesting and lesser-known features that can surprise even experienced programmers. Here are some fascinating facts about C that demonstrate its flexibility and unique behaviors. Fact 1: Switch Case Labels Inside If-Else Case labels in a switch statement can be placed inside if-else blocks due to the way switch works with jump labels − #include int main() { int x = 2, y = 2; switch(x) { case 1: ...

Read More

ldexp() function in C/C++

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

The ldexp() function in C computes the result of multiplying a floating-point number by an integral power of 2. It calculates x * 2^exp where x is a floating-point value and exp is an integer exponent. Syntax float ldexp(float x, int exp); double ldexp(double x, int exp); long double ldexp(long double x, int exp); Parameters x − The floating-point base value exp − The integer exponent representing power of 2 Return Value Returns x * 2^exp. If the result is too large to represent, it returns HUGE_VAL (infinity). Example ...

Read More

C qsort() vs C++ sort()

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

The qsort() function in C and sort() function in C++ are both used for sorting arrays, but they differ significantly in implementation, performance, and usage. Understanding these differences helps choose the right sorting approach for your program. C qsort() Syntax void qsort(void *base, size_t num, size_t size, int (*comparator)(const void*, const void*)); This function takes the base address of the array, number of elements, size of each element, and a comparator function. C++ sort() Syntax void sort(T first, T last, Compare c); Here T represents iterators, and the order of ...

Read More

What is the use of `%p` in printf in C?

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

In C, the %p format specifier is used with printf() to display pointer addresses in hexadecimal format. It provides a standard way to print memory addresses stored in pointer variables. Syntax printf("%p", pointer_variable); Example: Basic Pointer Address Printing Here's how to use %p to print the address of a variable − #include int main() { int x = 50; int *ptr = &x; printf("The address is: %p, the value is %d", ptr, *ptr); ...

Read More

setjump() and longjump() in C

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

In this section, we will see what are the setjmp() and longjmp() functions in C. The setjmp() and longjmp() functions are located in the setjmp.h library and provide a way to perform non-local jumps in C programs. Syntax #include int setjmp(jmp_buf env); void longjmp(jmp_buf env, int val); Parameters env − A buffer of type jmp_buf that stores the calling environment val − An integer value to be returned by setjmp() when longjmp() is called Return Value setjmp() − Returns 0 when called directly, or the value specified ...

Read More

Implicit initialization of variables with 0 or 1 in C

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

In C programming, uninitialized variables and partially initialized arrays follow specific rules for implicit initialization. Global variables, static variables, and array elements are automatically initialized to zero, while local variables contain garbage values if not explicitly initialized. Syntax // Global variables - implicitly initialized to 0 int global_var; int global_array[SIZE]; // Partial array initialization - remaining elements become 0 int array[SIZE] = {value1, value2, ...}; Example 1: Global Variables Implicit Initialization Global and static variables are automatically initialized to zero − #include int x, y; ...

Read More

Convert C/C++ program to Preprocessor code

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 545 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

Convert C/C++ code to assembly language

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

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 More

Compound Literals in C

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

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 More
Showing 41–50 of 388 articles
« Prev 1 3 4 5 6 7 39 Next »
Advertisements