karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 48 of 143

Read/Write structure to a file using C

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

In C programming, structures can be written to and read from files using the fwrite() and fread() functions. This allows you to store complex data types persistently and retrieve them later. fwrite() Syntax size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream); Parameters: ptr − A pointer to the data to be written size − Size in bytes of each element nmemb − Number of elements to write stream − Pointer to the FILE object fread() Syntax size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream); ...

Read More

When to use references vs. pointers in C/C++

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

In C programming, we work with pointers to access memory addresses and manipulate data indirectly. C does not have reference variables like C++, but understanding the difference helps when transitioning between languages. Syntax // Pointer declaration and usage datatype *pointer_name; pointer_name = &variable_name; Pointers in C Pointers are variables that store memory addresses of other variables. They provide indirect access to data and enable dynamic memory allocation. Example: Basic Pointer Usage #include int main() { int a = 8; int *ptr; ...

Read More

How to print a variable name in C?

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

In C programming, you can print the name of a variable as a string using the stringizing operator (#) within a macro. This technique is useful for debugging and logging purposes where you want to display variable names along with their values. Syntax #define MACRO_NAME(variable) #variable The # operator converts the macro parameter into a string literal. Example Here's how to create a macro that prints variable names − #include #define VariableName(name) #name int main() { int age = 25; char ...

Read More

Return type of getchar(), fgetc() and getc() in C

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

In C programming, the character input functions getchar(), fgetc(), and getc() all return an int value, not a char. This is crucial because they need to return both valid character values (0-255) and the special value EOF (-1) to indicate end-of-file or error conditions. Syntax int getchar(void); int fgetc(FILE *stream); int getc(FILE *stream); Why int Return Type? All three functions return int instead of char because − EOF handling: EOF is typically -1, which cannot fit in an unsigned char range (0-255) Error detection: Distinguishes between actual character values and error conditions ...

Read More

pow() function in C

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

The pow() function in C is used to calculate the power of a number. It computes base raised to the power of exponent and returns the result as a double. This function is declared in the math.h header file. Syntax double pow(double base, double exponent); Parameters base − The base value whose power is to be calculated exponent − The power value (exponent) Return Value Returns the value of base raised to the power of exponent as a double. Example 1: Basic Usage Here is a simple example ...

Read More

atexit() function in C/C++

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

The atexit() function in C is used to register functions that will be called automatically when the program terminates normally. These registered functions are executed in reverse order (LIFO - Last In, First Out) after the main function completes but before the program ends. This function is declared in the header file. Syntax int atexit(void (*function_name)(void)) Parameters: function_name − A pointer to the function that will be called at program termination. The function must take no parameters and return void. Return Value: Returns 0 on success, or a non-zero value if ...

Read More

Difference between strlen() and sizeof() for string in C

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

In C programming, strlen() and sizeof() are commonly used to work with strings, but they serve different purposes and return different values. Understanding their differences is crucial for effective string manipulation. strlen() Function The strlen() function is declared in string.h header file and calculates the actual length of a string by counting characters until it encounters the null terminator '\0'. Syntax size_t strlen(const char *string); string − The string whose length is to be calculated. Example #include #include int main() { char s1[10] ...

Read More

EOF, getc() and feof() in C

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

In C programming, EOF (End of File), getc(), and feof() are essential for file handling operations. EOF is a constant that indicates the end of a file stream, while getc() reads characters from files and feof() checks if the end-of-file indicator has been set. EOF (End of File) EOF stands for End of File and is a macro defined in . The getc() function returns EOF when it reaches the end of file or encounters an error. Syntax #define EOF (-1) Example: Using EOF with getc() Note: This example assumes a ...

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 395 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
Showing 471–480 of 1,421 articles
« Prev 1 46 47 48 49 50 143 Next »
Advertisements