Found 33676 Articles for Programming

What are the different operations on files in C language?

Bhanu Priya
Updated on 12-Dec-2024 16:59:58

8K+ Views

A file is a collection of data stored in secondary memory. The data is entered directly from the keyboard, files are used to store both information and programs. The following operations can be performed on files in the C language − Naming the file. Opening the file. Reading from the file. Writing into the file. Closing the file. File Naming and Opening The syntax for opening and naming file is as follows − FILE *File pointer; For ... Read More

What are the text files and binary files in C language?

Bhanu Priya
Updated on 12-Dec-2024 17:26:32

14K+ Views

A file is a collection of data stored in secondary memory, used for storing information that can be processed. Files allow data to be saved and retrieved later. They can store both programs and data, making file input and output operations crucial for reading from and writing to files. There are two types of files in C language which are as follows − Text file Binary File Text File Text files contain alphabets and numbers that are easily understood by humans. Errors in text files can be easily identified and ... Read More

Why files are needed in C programming language?

Bhanu Priya
Updated on 09-Mar-2021 10:04:35

4K+ Views

Files is collection of records (or) it is a place on hard disk, where data is stored permanently. By using C commands, we access the files in different ways.Need of files in C languageEntire data is lost when the program terminates and storing in a file will preserve your data even if the program terminates.If you want to enter a large amount of data, normally, it takes a lot of time to enter them all.If you have a file containing all the data, you can easily access the contents of the file by using few commands in C.You can easily ... Read More

Explain the Union to pointer in C language

Bhanu Priya
Updated on 09-Mar-2021 09:57:33

1K+ Views

A union is called as a memory location, which is shared by several variables of different data types.SyntaxThe syntax is as follows −union uniontag{    datatype member 1;    datatype member 2;    ----    ----    datatype member n; };For example, union sample{    int a;    float b;    char c; };Declaration of union variableGiven below are the respective declarations of union variable −Union sample{    int a;    float b;    char c; }s;Union{    int a;    float b;    char c; }s;Union sample{    int a;    float b;    char c; }; union sample ... Read More

Write a structure in local scope program using C language

Bhanu Priya
Updated on 09-Mar-2021 09:53:13

426 Views

Structure is a collection of different datatype variables, grouped together under a single name.Features of structureThe features of structure are explained below −It is possible to copy the contents of all structure elements of different datatypes to another structure variable of its type by using an assignment operator.For handling complex datatypes, it is better to create a structure within an another structure, which is called as the nested structures.It is possible to pass an entire structure, individual elements of a structure and an address of structure to a function.It is also possible to create the structure pointers.Declaration of structuresThe general ... Read More

Explain the concept of Uninitialized array accessing in C language

Bhanu Priya
Updated on 09-Mar-2021 09:48:46

1K+ Views

ProblemIn C language, is the program executed, if we use an uninitialized array?SolutionIf we use any uninitialized array, compiler will not generate any compilation and an execution error.If an array is uninitialized, you may get unpredictable result.So, it’s better we should always initialize the array elements with default values.Example ProgramFollowing is the C program of accessing an uninitialized array − Live Demo#include int main(void){    int a[4];    int b[4] = {1};    int c[4] = {1,2,3,4};    int i; //for loop counter    //printing all alements of all arrays    printf("Array a:");    for( i=0; i

What is out of bounds index in an array - C language?

Bhanu Priya
Updated on 09-Mar-2021 09:46:45

3K+ Views

Suppose you have an array with four elements. Then, an array indexing will be from 0 to 3, i.e., we can access elements from index 0 to 3.But, if we use index which is greater than 3, it will be called as an index out of bounds.If, we use an array index which is out of bounds, then the compiler will compile and even run. But, there is no guarantee for the correct result.Result can be not sure and it will start causing many problems. Hence, it is advised to be careful while using an array indexing.Example ProgramFollowing is the ... Read More

How to pass entire structure as an argument to function in C language?

Bhanu Priya
Updated on 09-Mar-2021 09:37:28

896 Views

Passing entire structure as an argument to function −Name of the structure variable is given as argument in function call.It is collected in another structure variable in function header.DisadvantageA copy of the entire structure is created again wasting memoryProgramFollowing program demonstrates passing an entire structure as an argument to function − Live Demo#include //Declaring structure// struct add{    int var1;    int var2; }a; //Declaring and returning Function// void show(struct add a){    //Declaring sum variable//    int sum;    //Arithmetic Operation//    sum=a.var1+a.var2;    //Printing O/p//    printf("Added value is %d", sum); } void main(){    //Declaring structure//    struct ... Read More

Declaring a structure with no members in C language

Bhanu Priya
Updated on 09-Mar-2021 09:35:11

1K+ Views

ProblemCan we declare a structure with no members in C, if yes what will be the size of that structure?SolutionYes, it is allowed in C programming language that we can declare a structure without any member and in that case the size of the structure with no members will be 0 (Zero). It will be a Zero size structure.Example Live Demo#include //structure with no members struct temp{ }; int main(){    //declaring structure variable    struct temp T;    printf("Size of T: %d", sizeof(T));    return 0; }OutputIn this C program, we are declaring a structure named "temp" without declare ... Read More

How to create a customized atoi() function in C language?

Bhanu Priya
Updated on 09-Mar-2021 09:31:03

185 Views

The atoi() is predefined function used to convert a numeric string to its integer value.Create a customized atoi()The atoi() only converts a numeric string to integer value, so we need to check the validity of the string.If this function encounters any non-numeric character in the given string, the conversion from string to integer will be stopped.Example Live Demo#include #include #include int main(){    int value;    char string1[] = "3567";    value = atoi(string1);    printf("String value = %s", string1);    printf("Integer value = %d", value);    char string2[] = "TutorialsPoint";    value = atoi(string2);    printf("String value ... Read More

Advertisements