Logo/

Flashcards: Basic Programming - Data Structures and File I/O.

Log in

Made with ScholarlyMake flashcards like these from your own notes

Flashcards: Basic Programming - Data Structures and File I/O.

Questions and answers

12 cards
  1. Question:What is a structure in programming?

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

  2. Question:What is an example of a structure?

    Answer:A record about a book in a library with properties such as title, author, subject, book ID, and publishing year.

  3. Question:How do you declare a struct?

    Answer:By specifying its data elements in arbitrary types using the struct keyword: struct Book { char* title; char* author; char* subject; char* ID; int year; };.

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

    Answer:By specifying the type of the struct and the name of the variable: struct Book fiction1;.

  5. Question:How do you initialize a struct?

    Answer:By assigning values to its data elements using curly braces: struct Book fiction1 = {"Harry Potter", "JKRowling", "fiction","Fi123", 2005};.

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

    Answer:Using the dot . operator: fiction1.title = "Harry Potter";.

  7. Question:What is the typedef keyword used for?

    Answer:To give a shorter name for the struct, making it easier to declare variables: typedef struct Book bk; bk fiction1;.

  8. Question:How do you calculate the size of a struct?

    Answer:By using the sizeof operator: printf("Size of book struct is %lu\n", sizeof(Book));.

  9. Question:Can struct variables be compared?

    Answer:No.

  10. Question:Can members of struct variables be compared?

    Answer:Yes.

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

    Answer:By specifying the type of the struct and the size of the array: Book fiction[5];.

  12. Question:How do you access elements of an array of structs?

    Answer:By using the dot . operator and the index of the element: fiction[1].title = "The Lord of the Rings";.