{"id":743,"date":"2010-02-17T11:49:04","date_gmt":"2010-02-17T11:49:04","guid":{"rendered":"http:\/\/www.codingfriends.com\/?p=743"},"modified":"2010-02-17T11:49:04","modified_gmt":"2010-02-17T11:49:04","slug":"struct-what-are-they-for","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2010\/02\/17\/struct-what-are-they-for\/","title":{"rendered":"struct &#8211; what are they for"},"content":{"rendered":"<p>A struct (structure) is a defined type that the user can define at compile time, for example if you want to have a user defined type that holds details of a database connection you could hold the hostname, username, password of the database connection within a structure (struct) without having to define 3 different variables you only have one that you need to fill in.<\/p>\n<p>For the above example of a database struct<\/p>\n<pre lang=\"cpp\">\r\nstruct database_connection\r\n{\r\n   char *username;\r\n   char *hostname;\r\n   char *password;\r\n};\r\n<\/pre>\n<p>then within the code you could create a new structure of this type and also fill in the details as<\/p>\n<pre lang=\"cpp\">\r\ndatabase_connection mydatabase;\r\nmydatabase.username = \"usernamebob\";\r\nmydatabase.hostname = \"localhost\";\r\nmydatabase.password = \"userpassword\";\r\n<\/pre>\n<p>and you just need to pass that struct to a function if you wanted to to do the connections e.g.<\/p>\n<pre lang=\"cpp\">\r\nbool dummyconnection(database_connection conn)\r\n{\r\n   createdatabase( conn.hostname, conn.username, conn.password);\r\n}\r\n<\/pre>\n<p>saves passing in three different parameters.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A struct (structure) is a defined type that the user can define at compile time, for example if you want to have a user defined type that holds details of a database connection you could hold the hostname, username, password of the database connection within a structure (struct) without having to define 3 different variables &hellip; <a href=\"https:\/\/www.codingfriends.com\/index.php\/2010\/02\/17\/struct-what-are-they-for\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">struct &#8211; what are they for<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[104],"class_list":["post-743","post","type-post","status-publish","format-standard","hentry","category-c_and_cpp","tag-struct"],"_links":{"self":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/743","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/comments?post=743"}],"version-history":[{"count":1,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/743\/revisions"}],"predecessor-version":[{"id":744,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/743\/revisions\/744"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=743"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=743"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=743"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}