Results 1 to 4 of 4

Thread: What is structure in C programming?

  1. #1
    Join Date
    Nov 2009
    Posts
    140

    What is structure in C programming?

    Hi Friends,

    According to me "Structure" is the most difficult part of the C programming. I have read somewhere that Structure is a type of the user defined data type, Is it true? OR it is similar to the "Class" from object oriented programming

    Anybody aware about structure in C programming? Please help me to understand the concept of the Structure from C language.

    I will appreciate you help...

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: What is structure in C programming?

    Hi friend,

    In C programming structure is behaves like record. Following is the syntax for the Stucture:
    struct nameOfstruct { type nameOffield; type nameOffield; type nameOffield;... }
    Example:

    struct EMP { char NAME[20]; int Sal; }

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: What is structure in C programming?

    Hi,

    Please go through the below example of the structure, in which program will read as well as print the 150 employee records:

    #include <stdio.h>
    #define SIZE 150

    typedef struct emp_type {
    char name[20];
    int ID;
    } emp_type;

    void print_empt(emp_type *s)
    {
    printf("Name: %s\n",
    s->name);
    printf("ID: %d\n", s->ID);
    }

    emp_type *
    read_emp(emp_type *s)
    { int ID;
    char name[20];

    printf("Enter ID and name\n");
    if (scanf("%d %19s",
    &ID, name) == EOF)
    return NULL;
    s->ID = ID;
    strcpy(s->name, name);
    return s;
    }

    int main(int argc, char *argv[])
    {
    emp_type employee[SIZE];
    int count = 0;
    int n;

    while (count < SIZE)
    {
    if (read_emp(emp +
    count) == NULL)
    break;
    count++;
    }

    for (n = 0; n < count; n++)
    print_emp(employee + n);
    exit(0);
    }

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: What is structure in C programming?

    Group of many variable within a single name is referred as Structure in C.i.e a structure is the easy method of biding many parts of interrelated
    information.

    Structures is defined using keyword known as struct. See below example:

    struct location{
    int home_number;
    char road_name[30];
    char city[40];
    };

Similar Threads

  1. Socket programming: Is any new Programming Language?
    By Kushan in forum Software Development
    Replies: 3
    Last Post: 14-11-2009, 11:13 AM
  2. Addition of a structure
    By Hashim in forum Software Development
    Replies: 3
    Last Post: 21-10-2009, 10:08 PM
  3. Pointer to structure in C
    By Jamaima in forum Software Development
    Replies: 3
    Last Post: 08-10-2009, 03:30 PM
  4. Replies: 3
    Last Post: 13-12-2008, 01:49 PM
  5. Structure of ntds.dit
    By Griffiths in forum Active Directory
    Replies: 3
    Last Post: 29-11-2008, 01:40 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,194,300.43904 seconds with 16 queries