Bhanu Priya has Published 1660 Articles

Explain malloc function in C programming

Bhanu Priya

Bhanu Priya

Updated on 06-Mar-2021 07:56:53

510 Views

ProblemWrite a C program to display and add the elements using dynamic memory allocation functions.SolutionIn C, the library function malloc allocates a block of memory in bytes at runtime. It returns a void pointer, which points to the base address of allocated memory and it leaves the memory uninitialized.Syntaxvoid *malloc ... Read More

Write a C program to check the atexit() function

Bhanu Priya

Bhanu Priya

Updated on 06-Mar-2021 07:52:09

357 Views

The atexit() is a function that allows the user to register a function that has to be called based on program termination.It is a predefined function that is included in stdlib header files.Example 1 Live Demo#include #include void welcome(void){    printf("Welcome to New, "); } void world(void){    printf("World"); } int ... Read More

Explain the functions fread() and fwrite() used in files in C

Bhanu Priya

Bhanu Priya

Updated on 06-Mar-2021 07:46:28

16K+ Views

ProblemWrite a C program for storing the details of 5 students into a file and print the same using fread() and fwrite()SolutionThe fread() function reads the entire record at a time.Syntaxfread( & structure variable, size of (structure variable), no of records, file pointer);Examplestruct emp{    int eno;    char ename ... Read More

Concatenating n characters from source string to destination string in C

Bhanu Priya

Bhanu Priya

Updated on 06-Mar-2021 07:44:01

655 Views

ProblemWrite a C program to concatenate n characters from source string to destination string using strncat library functionSolutionThe strcat functionThis function is used for combining or concatenating two strings.The length of the destination string must be greater than the source string.The resultant concatenated string will be in the source string.Syntaxstrcat ... Read More

Write a C program to compare two strings using strncmp library function

Bhanu Priya

Bhanu Priya

Updated on 06-Mar-2021 07:39:52

2K+ Views

Strncmp is a predefined library function present in string.h file, it used to compare two strings and display which string is greater.The strcmp fucntion (String comparison)This function compares 2 strings. It returns the ASCII difference of the first two non– matching characters in both the strings.Syntaxint strcmp (string1, string2);If the ... Read More

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

Bhanu Priya

Bhanu Priya

Updated on 06-Mar-2021 07:36:39

14K+ Views

ProblemHow to read a series of items that are present in a file and display the data in columns or tabular form using C ProgrammingSolutionCreate a file in write mode and write some series of information in the file and close it again open and display the series of data ... Read More

Write a C program to find total number of lines in an existing file

Bhanu Priya

Bhanu Priya

Updated on 06-Mar-2021 07:33:00

189 Views

Open a file in reading mode. If the file exists, then write a code to count the number of lines in a file. If the file does not exist, it displays an error that the file is not there.The file is a collection of records (or) It is a place ... Read More

Write a C program demonstrating examples on pointers

Bhanu Priya

Bhanu Priya

Updated on 06-Mar-2021 07:16:31

938 Views

A pointer is a variable that stores the address of another variable.Features of PointersPointer saves the memory space.The execution time of a pointer is faster because of direct access to memory location.With the help of pointers, the memory is accessed efficiently, i.e., memory is allocated and deallocated dynamically.Pointers are used ... Read More

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

Bhanu Priya

Bhanu Priya

Updated on 06-Mar-2021 07:10:26

704 Views

ProblemWrite a C program to define the structure and display the size and offsets of member variablesStructure − It is a collection of different datatype variables, grouped together under a single name.General form of structure declarationdatatype member1; struct tagname{    datatype member2;    datatype member n; };Here, struct  - keywordtagname ... Read More

Legal and illegal declaration and initializations in C

Bhanu Priya

Bhanu Priya

Updated on 06-Mar-2021 07:02:53

1K+ Views

ProblemMention some of the legal and illegal declarations and initializations while doing C programming?Before discussing the legal and illegal statements let’s see how to declare and initialize the variables in C.Variable declarationFollowing is the syntax of variable declaration −SyntaxDatatype v1, v2, … vn;Where v1, v2, ...vn are names of the ... Read More

Advertisements