ES101 - Lesson 9 : Structures

From Embedded Systems Learning Academy
Revision as of 23:04, 29 July 2013 by Preet (talk | contribs) (Type Define Structure)

Jump to: navigation, search

Objective

You will learn how to create structures.

Structures can help you group information together. For example, if you wish to ask for student age, ID, and name, you can group this data into a single structure that represents one student.

Video Demonstrates :

  • <Coming soon>

Type Define Structure

/* It is recommended to define your structure
 * before function declarations (outside main)
 */
typedef struct {   /* Syntax of struct type-define */
    int age;
    int id;        /* Put variables separated by semicolon */
    char name[32];
} student_t;       /* Name of the structure, _t means "type" */

void main()
{
    /* Your main() code here */
}

Declare and use structure

int main(void)
{
   
}

Passing structure to a function

Pass a copy

Pass by pointer

Assignment