Nishtha Thakur

Nishtha Thakur

398 Articles Published

Articles by Nishtha Thakur

Page 3 of 40

nextafter() and nexttoward() in C/C++

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

The nextafter() and nexttoward() functions in C are used to find the next representable floating-point value after a given number in a specified direction. These functions are part of the math.h library and are useful for precise floating-point arithmetic operations. Syntax double nextafter(double x, double y); float nextafterf(float x, float y); long double nextafterl(long double x, long double y); double nexttoward(double x, long double y); float nexttowardf(float x, long double y); long double nexttowardl(long double x, long double y); Parameters x − The starting value y − The direction value. The function ...

Read More

kbhit in C language

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

The kbhit() function in C checks if a key has been pressed on the keyboard without waiting for the Enter key. It returns a non-zero value if a key is available to be read, otherwise returns zero. However, kbhit() is non-standard and platform-specific (Windows/DOS only). Syntax int kbhit(void); Parameters None: The function takes no parameters. Return Value Returns a non-zero value if a key has been pressed. Returns zero if no key is pressed. Example Note: This example uses Windows-specific headers (conio.h) and will not ...

Read More

abs(), labs(), llabs() functions in C/C++

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

The C standard library provides different functions to calculate the absolute value of integers based on their data types. The abs(), labs(), and llabs() functions handle int, long, and long long data types respectively, returning the non-negative value of their arguments. Syntax int abs(int n); long labs(long n); long long llabs(long long n); The abs() Function The abs() function returns the absolute value of an integer argument. It is defined in stdlib.h and works with int type data − Example #include #include int main() { ...

Read More

trunc() , truncf() , truncl() in C language

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

In C, the trunc(), truncf(), and truncl() functions are used to truncate floating-point values, removing the fractional part and returning only the integer portion. These functions are part of the math.h library and are available in C99 and later standards. Installation: These functions require C99 or later. Compile with gcc -std=c99 -lm to link the math library. Syntax double trunc(double x); float truncf(float x); long double truncl(long double x); Parameters x − The floating-point value to be truncated Return Value Returns the truncated value (integer part) as ...

Read More

How to change the output of printf() in main()?

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

Here we will see how to change the output of the printf() function from main(). We will define a macro that will modify all printf() statements to use a different value than what is passed to it. We will use the #define macro to accomplish this task. This macro will be defined inside a function, allowing us to control when the printf() behavior changes. By calling the function from main(), we can control exactly when printf() starts behaving differently. Syntax #define printf(format, value) printf(format, replacement_value); Example In this example, we define a macro ...

Read More

Uninitialized primitive data types in C/C++

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

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

Write a C macro PRINT(x) which prints x

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

Here we will see how to define a macro called PRINT(x), and this will print whatever the value of x, passed as an argument. To solve this problem, we will use the stringize operator (#). Using this operator the x is converted into string, then by calling the printf() function internally, the value of x will be printed. Syntax #define PRINT(x) printf(#x) Example Let us see the example to get the better idea − #include #define PRINT(x) printf(#x) int main() { PRINT(Hello); ...

Read More

Scansets in C

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

Scansets in C are special format specifiers supported by the scanf() family of functions. They allow you to specify which characters to accept or reject when reading input. Scansets are represented by %[] and provide fine-grained control over input validation. Syntax %[characters] // Accept only specified characters %[^characters] // Accept all characters except specified ones %[character-range] // Accept characters within a range Example 1: Basic Character Set This example demonstrates how to read only uppercase letters using a character ...

Read More

Count number of elements in an array with MongoDB?

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

To count the number of elements in an array in MongoDB, use the $size operator within the aggregation framework. The $size operator returns the number of elements in the specified array field. Syntax db.collection.aggregate([ { $project: { fieldName: { $size: "$arrayField" } } } ]); Sample Data Let us create a sample collection with array data ? ...

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