C Programming/Structure Datatype

From Chorke Wiki
Revision as of 05:55, 5 February 2018 by Shahed (talk | contribs) (Created page with "# A structure in '''C''' is a collection of items of different types. Structure may be consider as a '''record''' like '''Pascal''' or a '''class''' in '''Java''' without meth...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
  1. A structure in C is a collection of items of different types. Structure may be consider as a record like Pascal or a class in Java without methods.
  2. Structures, or structs, are very useful in creating data structures larger and more complex
  3. Simply group various built-in data types into a structure.
  4. Object concepts was derived from Structure concept.
//main.c
#include <stdio.h>

struct student {
    char firstName[20];
    char lastName[20];
    char SSN[10];
    float gpa;
};

int main(void)
{
    struct student student_a;

    strcpy(student_a.firstName, "Deo");
    strcpy(student_a.lastName,  "Dum");
    strcpy(student_a.SSN,  "2333234" );
    student_a.gpa = 2009.20;

    printf( "First Name: %s\n", student_a.firstName );
    printf( "Last Name : %s\n", student_a.lastName );
    printf( "SNN       : %s\n", student_a.SSN );
    printf( "GPA       : %f\n", student_a.gpa );

    return 0;
}