[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-seo-685739-105":3,"detail-sidebar-cat-0-en-105":80,"doc-detail-685739-en":130,"doc-similar-685739":154},{"code":4,"msg":5,"data":6},0,"ok",{"site_id":7,"language":8,"slug":9,"title":10,"keywords":11,"description":12,"schema_data":13,"social_meta":73,"head_meta":75,"extra_data":77,"updated_unix":79},105,"en","lecture-09-c-structs-and-linked-lists-structs-in-c-bmp-headers-and-passing-structs-to-functions","Lecture 09 - C Structs and Linked Lists - Structs in C, BMP Headers, and Passing Structs to Functions","","Lecture 09 focuses on C structs and linked lists, explaining how structs package multiple data fields into one unit and how they differ from Java classes in terms of data access. The lecture covers defining and initializing structs, computing memory size with sizeof and addressing padding for alignment, and using the dot and -> operators for struct field access. It then applies structs to BMP files by defining HEADER/INFOHEADER layouts, reading binary header bytes via fread, and extracting width/height using pointer offsets, followed by passing structs and struct pointers to functions.",{"@graph":14,"@context":72},[15,34,55],{"@type":16,"itemListElement":17},"BreadcrumbList",[18,23,27,31],{"item":19,"name":20,"@type":21,"position":22},"https://docshare.wps.com","Home","ListItem",1,{"item":24,"name":25,"@type":21,"position":26},"https://docshare.wps.com/document/","Document",2,{"item":28,"name":29,"@type":21,"position":30},"https://docshare.wps.com/document/technology/","Technology",3,{"item":32,"name":10,"@type":21,"position":33},"https://docshare.wps.com/document/lecture-09-c-structs-and-linked-lists-structs-in-c-bmp-headers-and-passing-structs-to-functions/685739/",4,{"url":32,"name":10,"@type":35,"image":36,"author":41,"headline":10,"publisher":44,"fileFormat":47,"inLanguage":8,"description":12,"dateModified":48,"datePublished":49,"encodingFormat":47,"isAccessibleForFree":50,"interactionStatistic":51},"DigitalDocument",{"url":37,"@type":38,"width":39,"height":40},"https://docshare.wps.com/thumbnails/lecture-09-c-structs-and-linked-lists-structs-in-c-bmp-headers-and-passing-structs-to-functions/685739.png","ImageObject",300,407,{"name":42,"@type":43},"Eliana","Person",{"url":19,"name":45,"@type":46},"DocShare","Organization","application/pdf","2026-11-21","2026-11-07",true,{"@type":52,"interactionType":53,"userInteractionCount":33},"InteractionCounter",{"@type":54},"ViewAction",{"@type":56,"mainEntity":57},"FAQPage",[58,64,68],{"name":59,"@type":60,"acceptedAnswer":61},"What is the purpose of using structs in C?","Question",{"text":62,"@type":63},"Structs in C package several data fields into one unit and can be used to define types and variables of those types.","Answer",{"name":65,"@type":60,"acceptedAnswer":66},"How do you access struct fields in C when you have a struct pointer?",{"text":67,"@type":63},"Use the dot operator for direct struct variables, and use the -> operator when a pointer to the struct is available.",{"name":69,"@type":60,"acceptedAnswer":70},"How is BMP header information extracted using structs in this lecture?",{"text":71,"@type":63},"Allocate a 54-byte block, read raw bytes from the BMP file with fread, then use pointer offsets into the buffer to extract fields such as width and height.","https://schema.org",{"og:url":32,"og:type":74,"og:title":10,"og:site_name":45,"og:description":12},"article",{"robots":76,"canonical":32},"index,follow",{"doc_id":78,"site_id":7},685739,1794017220,{"code":4,"msg":81,"data":82},"success",[83,87,91,95,100,104,109,114,119,122,126],{"id":22,"doc_module":4,"doc_module_name":25,"category_name":84,"show_sort_weight":85,"slug":86},"Story & Novel",90,"story-novel",{"id":26,"doc_module":4,"doc_module_name":25,"category_name":88,"show_sort_weight":89,"slug":90},"Literature",80,"literature",{"id":33,"doc_module":4,"doc_module_name":25,"category_name":92,"show_sort_weight":93,"slug":94},"Exam",70,"exam",{"id":96,"doc_module":4,"doc_module_name":25,"category_name":97,"show_sort_weight":98,"slug":99},5,"Comic",60,"comic",{"id":101,"doc_module":4,"doc_module_name":25,"category_name":29,"show_sort_weight":102,"slug":103},6,50,"technology",{"id":105,"doc_module":4,"doc_module_name":25,"category_name":106,"show_sort_weight":107,"slug":108},7,"Healthcare",40,"healthcare",{"id":110,"doc_module":4,"doc_module_name":25,"category_name":111,"show_sort_weight":112,"slug":113},8,"Research & Report",30,"research-report",{"id":115,"doc_module":4,"doc_module_name":25,"category_name":116,"show_sort_weight":117,"slug":118},9,"Religion & Spirituality",20,"religion-spirituality",{"id":117,"doc_module":4,"doc_module_name":25,"category_name":120,"show_sort_weight":117,"slug":121},"World Cup","world-cup",{"id":123,"doc_module":4,"doc_module_name":25,"category_name":124,"show_sort_weight":123,"slug":125},10,"Lifestyle","lifestyle",{"id":127,"doc_module":4,"doc_module_name":25,"category_name":128,"show_sort_weight":96,"slug":129},19,"General","general",{"code":4,"msg":81,"data":131},{"doc_id":78,"user_id":132,"nickname":42,"user_avatar":133,"doc_module":4,"category_id":101,"category_name":29,"doc_title":10,"doc_description":12,"doc_content":134,"file_id":135,"file_url":136,"file_type":137,"file_size":138,"view_count":33,"is_deleted":4,"is_public":22,"is_downloadable":22,"audit_status":22,"page_count":139,"language":140,"language_code":8,"site_id":7,"html_lang":8,"table_of_contents":141,"faqs":142,"seo_title":143,"seo_description":12,"update_tm":79,"read_time":144,"preview_page_count":26,"preview_urls":145},4398048949847,"https://ap-avatar.wpscdn.com/avatar/400002536579ef2da7f?_k=1778318612642679267","Lecture 09  \nC Structs and Linked Lists  \nIn this lecture  \n• Structs in C  \n• 􀀁 operator  \n• Structs within BMP files  \n• Reading Header information from BMP files  \n• Passing structs to functions  \n• Passing pointer to structs  \n• Array of structs and Array of struct pointers  \n• Concept of a linked list  \n• Types of Linked List  \n• Implementation  \n• Further readings  \n• Exercises  \n• Answers  \nStructs in C  \nStructs in C are used to package several data fields into one unit. Structs can be used to define types and can be used to define variables of that type. C structs are different from Java classes. Java Classes “encapsulates” both state (data fields) and behavior (methods) with these fields being public, private or protected. C structs can only declare public data fields and all fields are accessible using the dot (.) operator. For example, we can define atypedef for a struct that contain two fields, var1 and var2 as:  \ntypedef struct {  \nunsigned int var1;  \nchar* var2;  \n} node;  \nA variable mynode of type node can be defined as  \nnode mynode;  \nfields within mynode variable can be accessed using,  \nmynode.var1 = 100;  \nmynode.var2 = malloc(20); =================== (1)  \nCopyright @ 2009 Ananda Gunawardena  \nThe amount of memory required to hold the variable mynode is equivalent to sizeof(unsigned int) + sizeof(char*) . You can also write sizeof(node) to find the how many bytes are required to hold a variable of size node. The amount of memory necessary to hold struct is not always the sum of the data sizes. It is possible that a padding may occur for word alignment. Note that sizes of specific data types are dependent on the machine you may be using. For example, on andrew domain machines([unix.andrew.cmu.edu](unix.andrew.cmu.edu)), an address variable is 4 bytes while in CS domain  \nmachines ([linux.gp.cs.cmu.edu](linux.gp.cs.cmu.edu)) an address variable is 8 bytes.  \nAs with initializing variables as they are declared, structs can also be initialized as  \nnode mynode = {100, malloc(20)};  \nDefine a struct that can hold a name(char*) and an int. Show how to read data into the struct using fscanf.  \n􀀂 operator  \nThere are two ways to access fields within a struct. Field within a struct can be accessed using the dot operator. However, if a pointer to the struct is given, then we can access fields within the struct using-> operator. For example,  \nnode mynode;  \nnode* ptr = &mynode;  \nptr􀀂var1 = 100;  \nptr􀀂var2 = malloc(20);  \nis equivalent to the code given above in (1) using the dot operator. The arrow operator will be used extensively in cases where a pointer to the struct is passed to a function instead of a copy.  \nCopyright @ 2009 Ananda Gunawardena  \nShow how to define a struct pointer and read data into a struct.  \nStructs within BMP files  \nAn interesting example of a struct type is header information stored in a bitmap (BMP) file. BMP, a format invented by Microsoft stores the image using a schema as follows. The first 14 bytes is reserved for information given by the following struct  \ntypedef struct {  \nunsigned short int type; /* BMP type identifier */  \nunsigned int size; /* size of the file in bytes*/  \nunsigned short int reserved1, reserved2;  \nunsigned int offset; /* starting address of the byte */  \n} HEADER;  \nThe next 40 bytes are reserved for a structure as follows .  \ntypedef struct {  \nunsigned int size; /* Header size in bytes */  \nint width,height; /* Width and height in pixels */  \nunsigned short int planes; /* Number of color planes */  \nunsigned short int bits; /* Bits per pixel */  \nunsigned int compression; /* Compression type */  \nunsigned int imagesize; /* Image size in bytes */  \nint xresolution,yresolution; /* Pixels per meter */  \nunsigned int ncolors; /* Number of colors */  \nunsigned int importantcolors; /* Important colors */  \n} INFOHEADER;  \nSuppose we are interested in extracting this information from a BMP file. First we need to read a block of 54 bytes using fread function as","cbCainls4xRZhbux","https://ap.wps.com/l/cbCainls4xRZhbux","pdf",118240,11,"English","# Structs in C\n## 􀀂 operator\n# Structs within BMP files\n## Reading Header Information from BMP file\n# Passing Structures to Functions\n# Further readings\n# Exercises\n## Answers","[{\"question\":\"What is the purpose of using structs in C?\",\"answer\":\"Structs in C package several data fields into one unit and can be used to define types and variables of those types.\"},{\"question\":\"How do you access struct fields in C when you have a struct pointer?\",\"answer\":\"Use the dot operator for direct struct variables, and use the -\\u003e operator when a pointer to the struct is available.\"},{\"question\":\"How is BMP header information extracted using structs in this lecture?\",\"answer\":\"Allocate a 54-byte block, read raw bytes from the BMP file with fread, then use pointer offsets into the buffer to extract fields such as width and height.\"}]","Lecture 09 - C Structs and Linked Lists - Structs in C, BMP Headers, and Passing Structs to Functions | PDF",28,[146,150],{"page_no":22,"url":147,"width":148,"height":149},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/252f3dd9e8a736a2de31b278bb75088d.webp",983,1272,{"page_no":26,"url":151,"width":152,"height":153},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/88be57bfaeca66ba0ad55d26222fc56e.webp",982,1270,{"list":155,"token":11},[156,162,168,174,180,186,192,198,204,210],{"doc_id":157,"doc_title":158,"file_type":137,"home_preview_img_url":159,"slug":160,"view_count":30,"category_name":29,"create_tm":161},732874,"Unit11-Linked Lists","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230031780339/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111579&Signature=aiSpndvT5WqQghJQtWebHoU%2Bfyw%3D","unit11-linked-lists",1795382671,{"doc_id":163,"doc_title":164,"file_type":137,"home_preview_img_url":165,"slug":166,"view_count":101,"category_name":29,"create_tm":167},685766,"Linked Lists - Fundamentals - Core Concepts and C++ Implementation Notes","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000198068/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111579&Signature=6u6EazsirNrcuRv8%2BWKZ8KVSHTY%3D","linked-lists-fundamentals-core-concepts-and-c-implementation-notes",1794017949,{"doc_id":169,"doc_title":170,"file_type":137,"home_preview_img_url":171,"slug":172,"view_count":33,"category_name":29,"create_tm":173},719604,"Lecture 17 - Linked List Data Structure (Part-II) - Double Linked List - Applications and Insertion","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230023515168/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111579&Signature=Q6og5n%2BmEDcbdgyTxmgWFWPcyh4%3D","lecture-17-linked-list-data-structure-part-ii-double-linked-list-applications-and-insertion",1795006749,{"doc_id":175,"doc_title":176,"file_type":137,"home_preview_img_url":177,"slug":178,"view_count":30,"category_name":29,"create_tm":179},732873,"Singly Linked Lists in C - Introduction and Traversal Example","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230031413508/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111579&Signature=omFlt357z4dhcTaGDiCeTZbKiCk%3D","singly-linked-lists-in-c-introduction-and-traversal-example",1795382670,{"doc_id":181,"doc_title":182,"file_type":137,"home_preview_img_url":183,"slug":184,"view_count":115,"category_name":29,"create_tm":185},692244,"How To Code in Go - How to learn and build Go programs","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230002689659/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111579&Signature=Z1C%2FTiuUsYh5vFT35Pp0NnSa5Go%3D","how-to-code-in-go-how-to-learn-and-build-go-programs",1794186705,{"doc_id":187,"doc_title":188,"file_type":137,"home_preview_img_url":189,"slug":190,"view_count":105,"category_name":29,"create_tm":191},685731,"Lecture Five - Linked List Structure","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229999689386/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111579&Signature=7NKly9%2BFjLdRCZVkniYRMIsiRWY%3D","lecture-five-linked-list-structure",1794017204,{"doc_id":193,"doc_title":194,"file_type":137,"home_preview_img_url":195,"slug":196,"view_count":26,"category_name":29,"create_tm":197},720226,"STM32 Datasheet and User Manual - Lecture 5 - Microprocessor-based Systems (E155)","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230024389715/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111579&Signature=E%2B%2Fl9Nx4A1795dajaC8vIETpfJg%3D","stm32-datasheet-and-user-manual-lecture-5-microprocessor-based-systems-e155",1795035878,{"doc_id":199,"doc_title":200,"file_type":137,"home_preview_img_url":201,"slug":202,"view_count":96,"category_name":29,"create_tm":203},685726,"L6b - Linked List Variations - Lecture 6b","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000185855/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111579&Signature=vmSyjieBngk%2BZ5Pj2AdIPtQ922M%3D","l6b-linked-list-variations-lecture-6b",1794017196,{"doc_id":205,"doc_title":206,"file_type":137,"home_preview_img_url":207,"slug":208,"view_count":96,"category_name":29,"create_tm":209},685667,"Implementing Singly Linked List in C++ - struct and pointers","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000175839/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111579&Signature=K7rtHJjp%2BBtQNDxl854z9c5ZKcY%3D","implementing-singly-linked-list-in-c-struct-and-pointers",1794016535,{"doc_id":211,"doc_title":212,"file_type":137,"home_preview_img_url":213,"slug":214,"view_count":30,"category_name":29,"create_tm":215},700989,"The Java Native Interface - Programmer’s Guide and Specification","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230012045673/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111579&Signature=dLx1vSv5Wsr61spCuTU7pCQs7FU%3D","the-java-native-interface-programmers-guide-and-specification",1794522639]