karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 48 of 143

Difference between "int main()" and "int main(void)" in C/C++?

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

In C programming, you might notice two different ways to declare the main function: int main() and int main(void). While both are valid, there is a subtle but important difference in how C treats them. Syntax int main() int main(void) Key Difference In C, int main() means the function can accept any number of arguments, while int main(void) explicitly specifies that the function takes no arguments. In C++, both forms are equivalent and mean "no arguments". Example 1: Function Without void When a function is declared without void, C allows it to ...

Read More

Heap overflow and Stack overflow in C

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

In C programming, memory management involves two primary areas: the heap and the stack. Both can experience overflow conditions that lead to program crashes or undefined behavior. Understanding these overflows is crucial for writing robust C programs. Heap Overflow The heap is a region of memory used for dynamic allocation. Functions like malloc(), calloc(), and realloc() allocate memory from the heap at runtime. Heap overflow occurs when the program exhausts available heap memory. This typically happens in two scenarios − Allocating Excessive Memory Attempting to allocate extremely large amounts of memory can cause heap overflow ...

Read More

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