Programming Articles - Page 1373 of 3366

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

593 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

5K+ 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

11K+ 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 high level I/O functions in C language?

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

5K+ 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

688 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

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

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

181 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 pass the address of structure as an argument to function in C language?

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

583 Views

Passing the address of structure as an argument to function −The Address of the structure is passed as an argument to the function.It is collected in a pointer to structure in function header.AdvantagesNo wastage of memory as there is no need of creating a copy againNo need of returning the values back as the function can access indirectly the entire structure and work on it.Example#include struct date{    int day;    int mon;    int yr; }; main (){    struct date d= {02, 01, 2010};    display (&d);    getch (); } display (struct date *dt){    printf("day = ... Read More

How to pass individual members of structure as arguments to function in C language?

Bhanu Priya
Updated on 09-Mar-2021 09:38:44

1K+ Views

Passing individual members as arguments to function −Each member is passed as an argument in the function call.They are collected independently in ordinary variables in function header.Example#include //Declaring structure// struct student{    int s1,s2,s3; }s[5]; //Declaring and returning Function// void addition(int a,int b,int c){    //Declaring sum variable and For loop variable//    int i,sum;    //Arithmetic Operation//    for(i=1;i

Explain structures using typedef keyword in C language

Bhanu Priya
Updated on 09-Mar-2021 09:36:17

578 Views

Typedef‘C’ allows to define new datatype names using the ‘typedef’ keyword. Using ‘typedef’, we cannot create a new datatype but define a new name for already existing type.Syntaxtypedef datatype newname;Exampletypedef int bhanu; int a; bhanu a; %dThis statement tells the compiler to recognize ‘bhanu’ as another name for ‘int’.‘bhanu’ is used to create another variable ‘a’ .‘bhanu a ‘declares ‘a’ as a variable of type ‘int’.Example#include main (){    typedef int hours;    hours h; //int h;    clrscr ();    printf("Enter hours”);    scanf ("%d”, &h);    printf("Minutes =%d”, h*60);    printf("Seconds = %d”, h*60*60);    getch (); ... Read More

Advertisements