// Some demo code showing structs

// Marc Chee (cs1511@cse.unsw.edu.au), July 2020

#include <stdio.h>

#define MAX_LENGTH 100

struct performer {
    char name[MAX_LENGTH];
    char description[MAX_LENGTH];
    int rank;
};

int main(void) {
    struct performer rm;
    strcpy(rm.name, "Rap Monster");
    strcpy(rm.description, "Leader");
    rm.rank = 1;

    printf("%s's description is: %s.\n", rm.name, rm.description);
    
    struct performer *rapper = &rm;
    
    // use -> to access a field of a struct through a pointer
    rapper->rank = 100;
}





Resource created Thursday 02 July 2020, 07:03:00 PM.

file: structsDemo.c


Back to top

COMP1511 20T2 (Programming Fundamentals) is powered by WebCMS3
CRICOS Provider No. 00098G