C Articles

Page 93 of 96

fseek() vs rewind() in C

Samual Sam
Samual Sam
Updated on 15-Mar-2026 3K+ Views

In C, both fseek() and rewind() are used to change the position of the file pointer, but they serve different purposes. fseek() provides flexible positioning anywhere in the file, while rewind() specifically moves the pointer back to the beginning. fseek() Function The fseek() function moves the file pointer to a specific position based on an offset and reference point. Syntax int fseek(FILE *stream, long int offset, int whence) Here are the parameters − stream − Pointer to the FILE object offset − Number of bytes to move from the reference position ...

Read More

calloc() versus malloc() in C

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 2K+ Views

In C, both malloc() and calloc() are used for dynamic memory allocation, but they have important differences in initialization and usage. Understanding when to use each function is crucial for effective memory management. Syntax void *malloc(size_t size); void *calloc(size_t number, size_t size); malloc() Function The malloc() function allocates a block of memory of the specified size in bytes. It does not initialize the allocated memory, leaving it with garbage values. Parameters size − Size of memory block to allocate in bytes Example #include #include ...

Read More

strxfrm() in C/C++

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 401 Views

The strxfrm() function transforms a source string according to the current locale's collating sequence and copies the transformed string to a destination buffer. It is declared in header file and is useful for locale-sensitive string comparisons. Syntax size_t strxfrm(char *destination, const char *source, size_t number); Parameters destination − Pointer to the destination buffer where transformed characters will be copied source − Pointer to the null-terminated source string to be transformed number − Maximum number of characters to copy to destination Return Value Returns the length of the transformed string ...

Read More

strcspn() in C

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 422 Views

The strcspn() function in C counts the number of characters in the initial segment of a string that do not match any character from a second string. It is declared in the string.h header file and returns the length of the initial segment of the first string before the first occurrence of any character from the second string. Syntax size_t strcspn(const char *string1, const char *string2); Parameters: string1 − The string to be scanned string2 − The string containing characters to search for in string1 Return Value: Returns the number of characters ...

Read More

What is the size of void pointer in C/C++ ?

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 15-Mar-2026 9K+ Views

The size of void pointer varies from system to system. If the system is 16-bit, size of void pointer is 2 bytes. If the system is 32-bit, size of void pointer is 4 bytes. If the system is 64-bit, size of void pointer is 8 bytes. This is because a pointer stores memory addresses, and the size depends on the system's addressing capability. Syntax To find the size of a void pointer, use the sizeof() operator: sizeof(void*) sizeof(pointer_variable) Example: Finding Size of Void Pointer The following example demonstrates how to find the size ...

Read More

fgets() and gets() in C

Samual Sam
Samual Sam
Updated on 15-Mar-2026 2K+ Views

In C, fgets() and gets() are functions used to read strings from input streams. The key difference is that fgets() is safe and checks array bounds, while gets() is unsafe and has been removed from C11 standard due to buffer overflow vulnerabilities. fgets() Function The fgets() function reads a string from a specified stream until a newline character or the specified limit is reached − Syntax char *fgets(char *string, int size, FILE *stream); Parameters: string − Pointer to character array where the string will be stored size − Maximum number of characters ...

Read More

size_t data type in C

Samual Sam
Samual Sam
Updated on 15-Mar-2026 9K+ Views

The size_t data type is an unsigned integral type in C that represents the size of any object in bytes. It is returned by the sizeof operator and commonly used for array indexing, loop counters, and memory size calculations. Since it represents sizes, size_t can never be negative. Syntax size_t variable_name; const size_t variable_name = value; Where variable_name is the name of the variable of type size_t. Example: Basic Usage of size_t Here's an example demonstrating size_t for array operations and size calculations − #include #include #include ...

Read More

isgreater() in C/C++

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 391 Views

In C programming, the isgreater() function is a type-generic macro used to compare two floating-point values safely. It is declared in the header file and returns a non-zero value (true) if the first argument is greater than the second, otherwise returns 0 (false). Unlike the regular > operator, isgreater() never raises floating-point exceptions. Syntax int isgreater(x, y); Parameters: x − First floating-point value to compare y − Second floating-point value to compare Return Value: Returns 1 if x is greater than y, otherwise returns 0. Example 1: Basic Usage with ...

Read More

strdup() and strdndup() in C/C++

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 8K+ Views

The functions strdup() and strndup() are used to duplicate strings in C. These functions allocate memory dynamically and create copies of existing strings. Note that these are POSIX functions, not part of the C standard library. Note: To use strdup() and strndup(), you may need to compile with -D_GNU_SOURCE flag or ensure your system supports POSIX extensions. strdup() Function The strdup() function duplicates an entire string by allocating memory and copying the string content. Syntax char *strdup(const char *string); Parameters string − Pointer to the null-terminated string to ...

Read More

Difference between %d and %i format specifier in C

Samual Sam
Samual Sam
Updated on 15-Mar-2026 3K+ Views

In C programming, both %d and %i are format specifiers used for integer values, but they behave differently when used with scanf() for input operations. For printf(), they work identically. Syntax printf("%d", integer_variable); // Decimal output printf("%i", integer_variable); // Integer output (same as %d for printf) scanf("%d", &integer_variable); // Reads decimal integers only scanf("%i", &integer_variable); // Reads decimal, octal, and hexadecimal Format Specifier %d The %d format specifier handles signed decimal integers. For printf(), it displays integers in decimal form. For scanf(), it only accepts decimal ...

Read More
Showing 921–930 of 953 articles
Advertisements