Found 1401 Articles for C

Explain the Format of C language

Bhanu Priya
Updated on 11-Mar-2021 08:35:46

2K+ Views

C programming is a general-purpose, procedural, imperative computer programming language. In C language, we see thatStatements are terminated with semicolons.C is case sensitiveIndentation is ignored by the compiler.Strings are placed in double quotes.Library functions are lowercase.Newlines are handled via Format of CThe format of C programming language is explained below −SemicolonsSemicolons are very important in C.It tells the compiler, where one statement ends and the next statement begins.If we fail to place the semicolon after each statement, you will get compilation errors.Case SensitivityC is a case sensitive language. Although, int compiles, "Int”, "INT” or any other variation will not be ... Read More

Check if the value entered is palindrome or not using C language

Bhanu Priya
Updated on 11-Mar-2021 08:28:05

224 Views

A palindrome is nothing but any word, number, sentence, or other sequence of characters that reads the same backward as forward.In this programming, we are trying to enter a number from console, and assign that number to temp variable.If number is greater than zero, apply the logic given below −while(n>0){    r=n%10;    sum=(sum*10)+r;    n=n/10; }If temp=sum, then the given number is a palindrome. Otherwise, it is not a palindrome.ExampleFollowing is the C program for verification of a value being palindrome −#include #include void main(){    int n, r, sum=0, temp;    printf("Enter a number: ");    scanf("%d", &n); ... Read More

Explain the concept of Sorting in C language

Bhanu Priya
Updated on 11-Mar-2021 07:51:40

4K+ Views

ProblemWhy sorting makes searching easier in C language? How can you judge the sorting efficiency in C?SolutionSorting is the process of arranging elements either in ascending (or) descending order.The term sorting came into existence when humans realized the importance of searching quickly.There are different things in life that we need to search for, particular record in database, roll numbers in a list, a number in a telephone directory, a specific page in a book etc.If the data was kept in an unordered and unsorted form, it becomes difficult to search a particular thing. But fortunately, the concept of sorting came ... Read More

Explain the Random accessing files in C language

Bhanu Priya
Updated on 11-Mar-2021 07:20:51

9K+ Views

Random accessing of files in C language can be done with the help of the following functions −ftell ( )rewind ( )fseek ( )ftell ( )It returns the current position of the file ptr.The syntax is as follows −int n = ftell (file pointer)For example, FILE *fp; int n; _____ _____ _____ n = ftell (fp);Note − ftell ( ) is used for counting the number of characters which are entered into a file.rewind ( )It makes file ptr move to beginning of the file.The syntax is as follows −rewind (file pointer);For example, FILE *fp;    -----    -----   ... Read More

What are the error handling techniques in C language?

Bhanu Priya
Updated on 11-Mar-2021 07:19:58

318 Views

Some of the errors that occurs in the files are listed below −Trying to read beyond end of file.Device over flow.Trying to open an invalid file.An invalid operation is performed by opening a file in a different mode.Functions for error handlingThe functions for error handling are as follows −ferror ( )perror ( )feof ( )ferror ( )It is for detecting an error while performing read or write operations.The syntax is as follows −int ferror (file pointer);For example, FILE *fp; if (ferror (fp)) printf ("error has occurred”);It returns zero, if it is a success and returns as non-zero in other cases.perror ... Read More

What are the high level I/O functions in C language?

Bhanu Priya
Updated on 11-Mar-2021 07:03:50

4K+ Views

I/O refers to the input - output functions in C language.High level I/OThese are easily understood by human beingsThe advantage is portability.Low level I/OThese are easily understood by computer.The advantage is that execution time is less.The disadvantage is that Non portability.High level I/O FunctionsThe high level input - output (I/O) functions are explained below −FunctionDescriptionfprintf ( )write data into a filefscanf ( )read data from a fileputc ( )/ fputc()write a character into a filegetc ( ) /fgetc()read a character from a fileputw ( )write a number into a filegetw ( )read number from a filefputs ( )write a string ... Read More

Explain the concept of union of structures in C language

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

581 Views

If the structure is nested inside a union, it is called as a union of structures. There is a possibility to create a union inside a structure in C programming language.ExampleFollowing is the C program for union of structures −#include struct x {    int a;    float b; }; union z{    struct x s; }; main ( ){    union z u;    u.s.a = 10;    u.s.b = 30.5;    printf("a=%d", u.s.a);    printf("b=%f", u.s.b);    getch ( ); }OutputWhen the above program is executed, it produces the following result −a= 10 b = 30.5ExampleGiven below is ... Read More

State the difference between structure and union with suitable example in C language

Bhanu Priya
Updated on 09-Mar-2021 09:51:16

1K+ Views

The differences between structures and unions in C language are explained below −S.NoStructureUnion1DefinitionStructure is heterogenous collection of data items grouped together under a single nameDefinitionA union is a memory location that is shared by several variables of different datatypes.2Syntax;struct tagname{    datatype member1;    datatype member2;    ----    ----    ---- };Syntax;union tagname{    datatype member1;    datatype member2;    ----    ----    ---- };3Eg;struct sample{    int a;    float b;    char c; };Eg;union sample{    int a;    float b;    char c; };4keyword − structkeyword − union5Memory allocationMemory allocation67Memory allocated is the sum of ... Read More

Give the clarity on Pointer structures with suitable example in C language

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

105 Views

Pointer to structure holds the address of an entire structure.Mainly, these are used to create the complex data structures such as linked lists, trees, graphs and so on.The members of the structure can be accessed by using a special operator called arrow operator ( -> ).DeclarationFollowing is the declaration for pointer to structure −struct tagname *ptr;For example, struct student *s;AccessingYou can access pointer to structure by using the following −Ptr-> membername;For example, s->sno, s->sname, s->marks;ExampleFollowing is the C program of the pointer structures −#include struct student{    int sno;    char sname[30];    float marks; }; main ( ){   ... Read More

How to access the pointer to structure in C language?

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

811 Views

Pointer to structure holds the address of an entire structure.Mainly, these are used to create the complex data structures such as linked lists, trees, graphs and so on.The members of the structure can be accessed by using a special operator called arrow operator ( -> ).DeclarationFollowing is the declaration for pointer to structure −struct tagname *ptr;For example, struct student *s;AccessingYou can access pointer to structure by using the following −Ptr-> membername;For example, s->sno, s->sname, s->marks;ExampleFollowing is the C program to access the pointer to structure −#include struct classroom{    int students[7]; }; int main(){    struct classroom clr = {2, ... Read More

Advertisements