Modal Box

Structure in C

Structure is the way to store different data types into a single variable.
Structure may be declared as following:
    struct <structure name>
   {
       datatype varname;
       datatype varname;
   }

  Example :
struct book
{
int pages;
float mrp;
}
Now we can declare the variable of book type too,
struct book b1,b2;

Program to take input and print details of three books using structure.

#include <stdio.h>
#include <conio.h>
void main()
{
     struct book
     {
         int pages;
         float mrp; 
      };
     
struct book b1,b2;        //how to take input in structure variable.         printf("enter the details for first book.");        scanf("%d", &b1.pages);         scanf("%f", &b1.mrp);        
printf("enter the details for second book.");         scanf("%d", &b2.pages);         scanf("%f", &b2.mrp);        
// similarly to print the structure variable.         printf("details for first book");         printf("pages= %d price=%f\n", b1.pages, b1.mrp);         printf("details for second book");         printf("pages= %d price=%f\n", b2.pages, b2.mrp); }

Video/ C Introduction

Watch video in full size
Wordpress Social Share Plugin powered by Ultimatelysocial