Bhanu Priya

Bhanu Priya

1,061 Articles Published

Articles by Bhanu Priya

Page 46 of 107

Concatenating n characters from source string to destination string in C

Bhanu Priya
Bhanu Priya
Updated on 15-Mar-2026 910 Views

In C programming, the strncat() function is used to concatenate a specified number of characters from a source string to the end of a destination string. This function provides more control than strcat() by allowing you to limit the number of characters to be concatenated. Syntax char *strncat(char *dest, const char *src, size_t n); Parameters dest − Pointer to the destination string src − Pointer to the source string n − Maximum number of characters to concatenate Example 1: Basic strncat() Usage This example demonstrates concatenating only 4 characters from ...

Read More

Write a C program to read a data from file and display

Bhanu Priya
Bhanu Priya
Updated on 15-Mar-2026 17K+ Views

In C programming, reading data from a file and displaying it is a fundamental file handling operation. This involves opening a file in read mode, reading its contents character by character, and formatting the output for better readability. Syntax FILE *fopen(const char *filename, const char *mode); int getc(FILE *stream); int fclose(FILE *stream); File Opening Modes Write mode ("w"): FILE *fp; fp = fopen("sample.txt", "w"); If the file does not exist, then a new file will be created. If the file exists, then old content gets erased and current content will ...

Read More

Write a C program to display the size and offset of structure members

Bhanu Priya
Bhanu Priya
Updated on 15-Mar-2026 1K+ Views

In C programming, structures allow us to group different data types under a single name. When working with structures, it's important to understand how memory is allocated for each member and their positions within the structure. The sizeof() operator helps determine the size of structure members, while the offsetof() macro shows the byte offset of each member from the beginning of the structure. Syntax struct structure_name { datatype member1; datatype member2; datatype memberN; }; sizeof(variable_or_type) offsetof(struct_type, member_name) Structure Declaration A structure ...

Read More

Legal and illegal declaration and initializations in C

Bhanu Priya
Bhanu Priya
Updated on 15-Mar-2026 2K+ Views

In C programming, variable declaration and initialization must follow specific rules. Understanding legal and illegal practices helps write error-free code and avoid compilation issues. Syntax // Variable Declaration datatype variable1, variable2, ..., variableN; // Variable Initialization datatype variable = value; Variable Declaration Variables can be declared in two scopes − Global declaration: Variables declared outside any function, accessible throughout the program. Local declaration: Variables declared inside a function, accessible only within that function. #include int globalVar; /* global declaration */ int main() { ...

Read More

How to calculate sum of random numbers in between 0 to 100 using files in C Programming?

Bhanu Priya
Bhanu Priya
Updated on 15-Mar-2026 2K+ Views

In this program, we generate random numbers between 0 and 100, calculate their sum, and store the result in a file. The sum will be different on each execution because random numbers are generated based on the current time. Syntax FILE *fptr = fopen("filename.txt", "w"); fprintf(fptr, "format_string", value); fclose(fptr); Algorithm The steps to calculate the sum of random numbers and store in a file are − Generate 100 random numbers between 1 and 100 Calculate the sum of all generated numbers Open a file in write mode Write the sum to the ...

Read More

Explain reference and pointer in C programming?

Bhanu Priya
Bhanu Priya
Updated on 15-Mar-2026 1K+ Views

In C programming, pointers are variables that store memory addresses of other variables. C does not have references like C++ − it only has pointers for indirect access to variables. Syntax datatype *pointer_name; pointer_name = &variable_name; Pointers in C Pointers store the memory address of another variable They can hold NULL values They enable pass by reference functionality They can be declared without initialization Use * operator to access the value at the address (dereference) Use & operator to get the address of a variable Example: Basic Pointer Operations This ...

Read More

Limitations of C programming language

Bhanu Priya
Bhanu Priya
Updated on 15-Mar-2026 4K+ Views

C programming language, despite being powerful and widely used, has several limitations when compared to modern programming languages. Understanding these limitations helps developers choose the right language for their projects. Key Limitations of C Programming 1. No Object-Oriented Programming Support C does not support object-oriented programming concepts like inheritance, polymorphism, encapsulation, and data abstraction. This makes it difficult to model real-world problems effectively. 2. No Runtime Error Detection C compiles the entire program before checking for errors, rather than detecting errors line by line. This can make debugging more challenging compared to interpreted languages. ...

Read More

How to delete the vowels from a given string using C language?

Bhanu Priya
Bhanu Priya
Updated on 15-Mar-2026 5K+ Views

In C, removing vowels from a string involves iterating through each character and shifting non-vowel characters to form a new string without vowels. This can be accomplished by checking each character against the vowel set and either skipping or keeping it. Syntax for(i=0; i

Read More

How to use Pre-defined mathematical function in C language?

Bhanu Priya
Bhanu Priya
Updated on 15-Mar-2026 354 Views

In C programming, pre-defined mathematical functions are available in the math.h header file. These functions provide various mathematical operations like power, square root, trigonometric calculations, logarithms, and more. They help perform complex mathematical calculations easily without implementing the logic from scratch. Syntax #include double function_name(double argument); Common Mathematical Functions Here are some commonly used mathematical functions − Function Description Example pow(x, y) Returns x raised to power y pow(2, 3) = 8.0 sqrt(x) Returns square root of x sqrt(16) = 4.0 cbrt(x) Returns cube ...

Read More

What are the input and output for strings in C language?

Bhanu Priya
Bhanu Priya
Updated on 15-Mar-2026 5K+ Views

An array of characters (or) collection of characters is called a string. In C programming, strings are null-terminated character arrays that end with the special character '\0'. Syntax // Input functions for strings scanf("%s", string_name); fgets(string_name, size, stdin); // Output functions for strings printf("%s", string_name); puts(string_name); Method 1: Using scanf() and printf() The scanf() function reads strings until it encounters whitespace, while printf() displays the complete string − #include int main() { char name[30]; printf("Enter your name: "); ...

Read More
Showing 451–460 of 1,061 articles
« Prev 1 44 45 46 47 48 107 Next »
Advertisements