Logo/

Data Structures and File I/O in Basic Programming

Log in

Made with ScholarlyMake flashcards like these from your own notes

Data Structures and File I/O in Basic Programming

Questions and answers

8 cards
  1. Question:What is a structure?

    Answer:A user-defined data type that combines a limited number of data elements into a unified data unit.

  2. Question:What is the syntax for declaring a struct?

    Answer:struct Book { char* title; char* author; char* subject; char* ID; int year; };

  3. Question:How do you declare a struct variable?

    Answer:struct Book fiction1;

  4. Question:How do you initialize a struct?

    Answer:Declare the variable and assign values to each attribute, e.g. struct Book fiction1 = { "Harry Potter", "JKRowling", "fiction", "Fi123", 2005 };

  5. Question:How do you access a member of a struct?

    Answer:Use the "." operator, e.g. fiction1.title

  6. Question:What is the purpose of typedef with structs?

    Answer:To give a shorter name for the struct, e.g. typedef struct Book bk; bk fiction1; or typedef struct { char* title; char* author; char* subject; char* ID; int year; } Book; Book fiction2;

  7. Question:How do you declare an array of structs?

    Answer:Book fiction[5];

  8. Question:What is the size of a struct?

    Answer:The size of a struct can be found using the sizeof() function, e.g. printf("Size of book struct is %lu\n", sizeof(Book));