C Articles

Page 82 of 96

C function argument and return values

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

In C programming, functions can be categorized based on two criteria: whether they accept arguments (parameters) and whether they return a value. This gives us four distinct types of functions that cover all possible combinations. Syntax return_type function_name(parameter_list) { // Function body return value; // Optional, depends on return_type } Types of Functions Function with no arguments and no return value − Takes no input and returns nothing (void) Function with no arguments but returns a value − Takes no input but returns a value ...

Read More

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

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

ldexp() function in C/C++

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

Convert an int to ASCII character in C/C++

Nishu Kumari
Nishu Kumari
Updated on 15-Mar-2026 38K+ Views

In C, every character like 'A', 'b', '3', or '@' is stored as a number called its ASCII value. For example, 'A' is 65, and 'a' is 97. Given an integer like 97, we can convert it to its corresponding ASCII character which is 'a'. Syntax char character = (char)asciiValue; We can convert an integer to an ASCII character using simple methods. Here are two common approaches − Typecasting to Convert int to ASCII Character Using printf for int to ASCII Conversion Method 1: Typecasting to Convert int to ASCII Character ...

Read More

How to find the size of an int[] in C/C++?

Nishu Kumari
Nishu Kumari
Updated on 15-Mar-2026 9K+ Views

In C programming, finding the size of a statically declared int[] array means determining how many elements it contains. This is different from finding the memory size − we want the element count. The sizeof operator is the primary method for this in C. Syntax int array_length = sizeof(array) / sizeof(array[0]); Method 1: Using sizeof Operator The sizeof operator returns the total memory occupied by an array in bytes. Dividing this by the size of one element gives us the number of elements. This works only for statically declared arrays − #include ...

Read More

Modulus of two float or double numbers using C

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

In C, to find the modulus (remainder) of two floating-point or double numbers, we use the remainder() function from the math library. Unlike the % operator which only works with integers, remainder() handles floating-point arithmetic. Syntax double remainder(double x, double y); float remainderf(float x, float y); long double remainderl(long double x, long double y); Parameters x − The numerator (dividend) y − The denominator (divisor) Return Value Returns the floating-point remainder of x/y. The remainder is calculated as: remainder(x, y) = x - rquote * y ...

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

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
Showing 811–820 of 953 articles
« Prev 1 80 81 82 83 84 96 Next »
Advertisements