answersLogoWhite

0

What are structures C programming?

User Avatar

Anonymous

15y ago
Updated: 8/16/2019

Presuming you mean:

"What are structures in C (programming)"

(Data) Structures are a simple way to organize information.

Example:

Suppose you want to make a program that does arithmetic operations on fractions.

Since each fraction can be represented by a nominator and a denominator for each fraction you have you need two integers (or other numeric variable type), the solution with no structs would be to create two arrays , one for the nominators and the other for the denominators:

int nominators[10];

int denominators[10];

The problem with this approach is that it is prone to programmer errors the relation between nominators and denominators is not enforced.

By using structs one could enforce the relation of a nominator with its denominator:

struct Fraction

{

int nominator;

int denominator;

};

This is a struct definition, it defines a new variable type that consists of two int variables

named nominator and denominator. So now you can write this:

struct Fraction fractions[10];

This makes it simpler for the programmer to handle the data.

Structs are declared as any other variable type:

struct Fraction fraction; //The keyword struct is necessary

In order to get a struct's inner variables (members is the usual term) you must use the '.'(full-stop) operator as such:

fraction.nominator = 0; //This will set the nominator member to 0

The initialization of a struct a bit awkward at first:

struct Fraction fraction = {1,2};

This will initialize the nominator member of the variable fraction to 1

and the denominator member to 2.

Hope this solves your query.

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

Examples on structures of C programming?

'struct tm' (time.h) and 'FILE' (stdio.h)


Is 'c' a structured language?

Yes, in C, you can use the standard programming structures (sequence, selection, repetition).


Why c is call structured programming?

Because you can use programming structures, namely: sequence, selection (if, switch) and repetition (while, for, do-while)


What is the index of structures and unions in C programming?

There is no such thing. Structs and unions have fields, which can be accessed by their names.


What do you think is the better type of language for writing complex data structures?

structured programming language ex:c,c++


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)


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 is c and c in computer programming?

C and C++ are both high-level programming languages.


What is the Pascal programming language data structure?

In Pascal, data structures are implemented with recorddata types. A record is synonymous with the structdata type in C, or the class data type in C++.


Create a spiral in C programming?

create spiral in c programming?


What has the author Robert Lafore written?

Robert Lafore has written: 'Object-oriented programming in Microsoft C++' -- subject(s): Object-oriented programming (Computer science), C++ (Computer program language), C. 'Microsoft C. Programming for the I.B.M.Personal Computer' 'Object-oriented programming in C++' 'Windows Programming Made Ridiculously Easy Book' 'The Waite Group's C Programming Using Turbo C++ (The Waite Group)' 'Microsoft C programming for the IBM' 'The Waite Group's Microsoft C programming for the PC' -- subject(s): C (Computer program language), IBM microcomputers, Microsoft C (Computer program), Microsoft C., Programming


What is a C compiler as used in C programming?

In C programming, C compiler is user to translate C source into C object module.