This blog is under construction

Sunday 13 May 2012

What is a structure?

A structure is a user defined compound data type.  It is also defined as the elements of different data types grouped under a common name.  Below is the general form of a structure.

struct  <name> {
      data_type   <data_element1>;
      -------------
};

Consider the following example,
struct value {
          int x;
          float y;
};

Above is the definition for a structure named value and it contains an integer variable x and float variable y as its structure member.

Structure example in C:

  #include <stdio.h> 
  struct student {
        char name[100];
        int rollno;
        int age;
  };

  int main() {
        /* s1 is a variable of type struct student */
        struct student s1 = {"jp", 1010101, 23};  // assigning values to variable s1
        printf("Name: %s\n", s1.name);
        printf("Roll No.:%d\n", s1.rollno);
        printf("Age: %d\n", s1.age);
        return 0;
  }

  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Name: jp
  Roll No.:1010101
  Age: 23



1 comment:

  1. Dell Laptop Service center are giving repair service at the door. We should high quality Dell out of warranty Laptop Repair, removal of virus, screen removal, wireless network set up, battery removal, motherboard replacement to several other are offered at budget friendly price and it’s Negotiable. We can fix them all in time by our well experience and certified technicians. If you want to repair your laptop in front of your eyesight, than you may call us: 7217871051

    ReplyDelete