Struct Introduction Tutorial (revision 120925-r01KI)

Return to Lab 02

  • Create cobastruct.c file and fill it with the below content. Replace [nama_anda] with your name (example: Ramot Stephanus) and [NPM_anda] with your student ID (example: 1202000818) without the square brackets. Replace TOKEN with your token.
    $ vi cobastruct.c

    // Saya, [nama_anda] dengan NPM [NPM_anda], 
    // mengetik sendiri program ini.
    typedef struct person
       char *name;
       int age;
    } PERSON;
    int main()
       PERSON pp; = "John Smith";
       pp.age = 25;
       return 0;
  • Compile the program to be executable cobastruct.
  • Run cobastruct and record the output to cobastruct.txt, the result must be exactly the same with below:
    $ cat cobastruct.txt

    John Smith
  • From this tutorial, you are expected to understand that struct functions just like Object in Java programming language.
  • This is the end of struct tutorial.

Return to Lab 02
Kembali ke Wiki