This blog is under construction

Wednesday 8 January 2014

Array of structures

We can create array of structures similar to creating array of any primitive data types. Below is the general form of declaration for array of structure.
struct  <structure_name>  <array_name>[SIZE];

Consider the following example
struct student {
char name[32];
int age, rollno;
};

struct student arr[2];

Here, arr is an array of 2 structure elements.

Let us see how to initialize an array of structures.

Method 1:
struct student arr[2] = { {"Tom", 10, 101}, {"Jerry", 11, 102} };

Method 2:
strcpy(arr[0].name, "Tom");
arr[0].age = 10;
arr[0].rollno = 101;

strcpy(arr[1].name, "Jerry");
arr[1].age = 11;
arr[1].rollno = 102;

Apart from the above, we are allowed to do partial initialization for structure elements in an array.

Consider the following,
struct student arr[2] = {{"Tom", 10, 101}, {"Jerry"}};

In the above example, we have done partial initialization for second element in the structure array (ie) we have assigned value for the structure member name, whereas the structure members age and rollno are left uninitialized.  We can assign values to those uninitialized structure members whenever it is needed.

arr[1].age = 11;
arr[1].rollno = 101;

If the array of structure is declared as global variable, then structure members in each structure element are initialized to 0 by default.  Similarly, if any structure element is partially initialized(few structure members alone initialized), then the left over structure members are initialized to 0 by default.

Array of structures example in C

  #include <stdio.h>
  #include <string.h>
  struct student {
        char name[32];
        int age, rollno;
  };
  struct student arr1[2];  // global declaration for array of structures

  /* prints the contents of the given array */
  void printDetails(struct student arr[2]) {
        int i;
        for (i = 0; i < 2; i++) {
                printf("Name: %s\n", arr[i].name);
                printf("Age: %d Rollno: %d\n", arr[i].age, arr[i].rollno);
        }
        printf("\n");
        return;
  }

  int main() {
        /* complete initialization */
        struct student arr2[2] = {{"Ram", 10, 101}, {"Raj", 11, 102}};
        /* partial initialization */
        struct student arr3[2] = {{"Jack", 10, 107}, {"Rose"}};
        struct student arr4[2];

        /* initializing array arr4 */
        strcpy(arr4[0].name, "Mike");
        arr4[0].age = 10;
        arr4[0].rollno = 105;
        strcpy(arr4[1].name, "Tyson");
        arr4[1].age = 11;
        arr4[1].rollno = 106;

        /* printing the contents of arr1 */
        printf("Contents of arr1:(uninitialized global variable)\n");
        printDetails(arr1);

        /* printing the contents of arr2 */
        printf("Contents of arr2:\n");
        printDetails(arr2);

        /* printing the contents of partially initialized array arr3 */
        printf("Contents of arr3:(arr3[1] - partially initialized)\n");
        printDetails(arr3);
        arr3[1].age = 10;
        arr3[1].rollno = 108;

        /* printing the contents of the array after above updation */
        printf("printing the contents of arr3 after updation:\n");
        printDetails(arr3);

        /* printing the contents of arr4 */
        printf("Contents of arr4:\n");
        printDetails(arr4);
        return 0;
  }

  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Contents of arr1:(uninitialized global variable)
  Name: 
  Age: 0 Rollno: 0
  Name: 
  Age: 0 Rollno: 0

  Contents of arr2:
  Name: Ram
  Age: 10 Rollno: 101
  Name: Raj
  Age: 11 Rollno: 102

  Contents of arr3:(arr3[1] - partially initialized)
  Name: Jack
  Age: 10 Rollno: 107
  Name: Rose
  Age: 0 Rollno: 0

  printing the contents of arr3 after updation:
  Name: Jack
  Age: 10 Rollno: 107
  Name: Rose
  Age: 10 Rollno: 108

  Contents of arr4:
  Name: Mike
  Age: 10 Rollno: 105
  Name: Tyson
  Age: 11 Rollno: 106



4 comments:

  1. Hello Everyone !

    USA SSN Leads/Dead Fullz available, along with Driving License/ID Number with good connectivity.

    All SSN's are Tested & Verified.

    **DETAILS IN LEADS/FULLZ**

    ->FULL NAME
    ->SSN
    ->DATE OF BIRTH
    ->DRIVING LICENSE NUMBER
    ->ADDRESS WITH ZIP
    ->PHONE NUMBER, EMAIL
    ->EMPLOYEE DETAILS

    *Price for SSN lead $2
    *You can ask for sample before any deal
    *If you buy in bulk, will give you discount
    *Sampling is just for serious buyers

    ->Hope for the long term business
    ->You can buy for your specific states too

    **Contact 24/7**

    Whatsapp > +923172721122

    Email > leads.sellers1212@gmail.com

    Telegram > @leadsupplier

    ICQ > 752822040

    ReplyDelete
  2. 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
  3. **SELLING SSN+DOB FULLZ**

    CONTACT 24/7
    Telegram > @leadsupplier
    ICQ > 752822040
    Email > leads.sellers1212@gmail.com

    >>1$ each without DL/ID number
    >>2$ each with DL
    >>5$ each for premium (also included relative info)

    Price will be reduce in Bulk order

    FORMAT OF LEADS/FULLZ/PROS

    ->FULL NAME
    ->SSN
    ->DATE OF BIRTH
    ->DRIVING LICENSE NUMBER WITH EXPIRY DATE
    ->COMPLETE ADDRESS
    ->PHONE NUMBER, EMAIL, I.P ADDRESS
    ->EMPLOYMENT DETAILS
    ->REALTIONSHIP DETAILS
    ->MORTGAGE INFO
    ->BANK ACCOUNT DETAILS

    >All Leads are Spammed & Verified.
    >Fresh spammed data of USA Credit Bureau
    >Good credit Scores, 700 minimum scores
    >Invalid info found, will be replaced.
    >Payment mode BTC, ETH, LTC, PayPal, USDT & PERFECT MONEY

    ''OTHER GADGETS PROVIDING''

    >SSN+DOB Fullz
    >CC with CVV
    >Photo ID's
    >Dead Fullz
    >Carding Tutorials
    >Hacking Tutorials
    >SMTP Linux Root
    >DUMPS with pins track 1 and 2
    >Sock Tools
    >Server I.P's
    >HQ Emails with passwords

    Contact 24/7

    Email > leads.sellers1212@gmail.com
    Telegram > @leadsupplier
    ICQ > 752822040

    ReplyDelete
  4. Very Fresh, Legit & Genuine Stuff available now
    Freshly spammed from HIGH INCOME Databases
    USA, UK, Canada States available
    All info included SSN/SIN DOB DL
    Fullz will be high credit scores 680 to 700+
    Stuff will be fresh, never sold before

    +92 3.1.7 2.7.2 1.1.2.2 WhatsApp/Tele-gram
    7.5.2.8.2.2.0.4.0 I.C.Q
    @peeterhacks Skype&WickrMe
    exploit dot tools4u at gmail dot com

    CC FULLZ with CVV's
    DUMPS with Pins
    Combos
    Logs
    Office365 Emails & Logs
    Spamming Tools & Tutorials (SMTP's, RDP's, C-panels, Brutes, Scripting, etc)
    Ha-cking stuff with complete tools, Guides, Ebooks & guidance
    Carding fresh Methods, Loan Methods, Carding Cash-out Methods
    Carding Tutorials, Transfers, top-up's
    Kali Linux with Termex & Python
    Keyloggers, Shells, RAT's
    I.p's, Proxies, Server I.p's

    Many other stuff we can provide on demand
    Here we're

    @killhacks ICQ&Tele.gram
    +92 317272 1122 WhatsApp

    ReplyDelete