answersLogoWhite

0


Best Answer

You declare a structure as follows:

struct name {

typename_1 member_name_1; typename_2 member_name_2;

// additional members...

};

User Avatar

Wiki User

6y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

Initally, a structure must be defined with any and all variables (and/or functions) which should be included. The primary use for a structure is to contain instances of variable types - for example an integer - which will contain different information. A structure can contain any variable type (int, string, bool e.t.c)

To declare a structure, it should look like this:

struct NameOfStructure

{

variable_type name_of_variable1;

variable_type name_of_variable2;

};

Once the structure is declared (similar to above), it needs to be called, and an instance of the structure needs to be created.

Note: If the structure has been created in an external header file, the header.hpp needs to be include. This can be done like so:

#include name_of_header.hpp

Within the program, and to call a structure, it should look something like this:

NameOfStructure structure;

The structure name becomes a variable type, and you use it as such. The name 'structure' therefore will become a useable instance which contains all data members which were implemented when the structure was created.

For example, if the structure contained:

int number;

int box;

to access these members (using the aforementioned structure), it should look like this:

structure.number;

This directly accesses the data which is held within the member 'number,' and can be manipulated as such.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

ghbhn

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How can structures be declared and used in c program?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Where is the global declaration section of a c plus plus program?

Anything declared outside of a function is global.


Why you use C language in electronic engineering?

C is a structured language. Controlled structures used in electronic engineering can be programmed well by C. C++ and C sharp are also used sometimes.


What type of a program is used in order to enter c source code?

What type of a program is used in order to enter C source code


Why are all Header Files not declared in every C Program?

We only include the headers we actually use. It would be impractical to include every single header in every single program.


Is a left brace in a c program always followed by a right brace later in the program?

Yes. Braces are used to group similar pieces of code in a C program

Related questions

C program for comparison of dates using structures?

C program for comparison of dates using structures


What has the author Thomas Plum written?

Thomas Plum has written: 'Learning to program in C' 'Efficient C' 'Reliable data structures in C' -- subject(s): C (Computer program language), Data structures (Computer science)


What has the author M Main written?

M. Main has written: 'Data structures & other objects using C++' -- subject(s): C++ (Computer program language), Data structures (Computer science), Object-oriented programming (Computer science) 'Data structures and other objects using Java' -- subject(s): Java (Computer program language), Data structures (Computer science) 'Data structures & other objects using C++' -- subject(s): C++ (Computer program language), Data structures (Computer science), Object-oriented programming (Computer science)


Where is the global declaration section of a c plus plus program?

Anything declared outside of a function is global.


What has the author Yedidyah Langsam written?

Yedidyah Langsam has written: 'Data structures using Cand C[plus plus]' -- subject(s): C (Computer program language), Data structures (Computer science)


What has the author Larry R Nyhoff written?

Larry R. Nyhoff has written: 'Instructor's manual containing lecture notes, transparency masters, and sample test questions and answers' 'Problem solving with Fortran 77' -- subject(s): FORTRAN 77 (Computer program language) 'ADTs, data structures, and problem solving with C++' -- subject(s): C++ (Computer program language), Data structures (Computer science) 'Data structures and program design in Pascal' -- subject(s): Pascal (Computer program language), Data structures (Computer science) 'Programming in C++ for engineering and science' -- subject(s): TECHNOLOGY & ENGINEERING / Electrical, C++ (Computer program language), Data processing, COMPUTERS / Programming Languages / General, Science, MATHEMATICS / General, Engineering 'ADTs, Data Structures, and Problem Solving with C++ (2nd Edition) (Alan R. Apt Books)'


What is main function used in c?

if you do not used main function in c program when errors are accrued


What is the compiler that is used in C?

A program that translates source program into object code.


What has the author Richard F Gilberg written?

Richard F. Gilberg has written: 'Data structures' -- subject(s): C&& (Computer program language), Data structures (Computer science)


Why you use C language in electronic engineering?

C is a structured language. Controlled structures used in electronic engineering can be programmed well by C. C++ and C sharp are also used sometimes.


How do you write a c program to store 5 names in structures and print them each in one line?

With a text editor, and some basic knowledge of the C programming language.


What type of a program is used in order to enter c source code?

What type of a program is used in order to enter C source code