Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Struct (C programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|C keyword for defining a structured data type}} {{lowercase}} In the [[C programming language]], '''struct''' is the keyword used to define a [[composite data type|composite]], a.k.a. [[Record (computer science)|record]], [[data type]] {{endash}} a named set of values that occupy a block of memory. It allows for the different values to be accessed via a single [[identifier]], often a [[pointer (computer programming)|pointer]]. A struct can contain other data types so is used for mixed-data-type records. For example a bank customer struct might contains fields: name, address, telephone, balance. A struct occupies a ''contiguous block'' of memory, usually delimited (sized) by word-length boundaries. It corresponds to the similarly named feature available in some [[assembly language|assemblers]] for Intel processors. Being a block of contiguous memory, each field within a struct is located at a certain fixed offset from the start. The [[sizeof]] operator results in the number of bytes needed to store a particular struct, just as it does for a [[primitive data type]]. The alignment of particular fields in the struct (with respect to [[Word (computer architecture)|word]] boundaries) is implementation-specific and may include padding. Modern compilers typically support the <code>#pragma pack</code> directive, which sets the size in bytes for alignment.<ref>{{Cite web|url=https://stackoverflow.com/questions/2748995/struct-memory-layout-in-c|title=Struct memory layout in C|website=Stack Overflow}}</ref> The C struct feature was derived from the same-named concept in [[ALGOL 68]].<ref name="sigplan">{{cite journal | first = Dennis M.| last = Ritchie | authorlink = Dennis Ritchie | title = The Development of the C Language | date = March 1993 | journal = ACM SIGPLAN Notices | volume = 28 | issue = 3 | pages = 201β208 | url = http://www.bell-labs.com/usr/dmr/www/chist.html | doi = 10.1145/155360.155580 | quote = The scheme of type composition adopted by C owes considerable debt to Algol 68, although it did not, perhaps, emerge in a form that Algol's adherents would approve of. The central notion I captured from Algol was a type structure based on atomic types (including structures), composed into arrays, pointers (references), and functions (procedures). Algol 68's concept of unions and casts also had an influence that appeared later.| doi-access = free }}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)