Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Structs Application | Introduction to Structs
C Structs
course content

Conteúdo do Curso

C Structs

C Structs

1. Introduction to Structs
2. Pointers and Structs
3. Structs and Memory
4. Advanced Structs Usage
5. Implementing Data Structures

Structs Application

When designing programs, a very important step is the choice of the representation of the data that we will manage.

For example, you want to write a simple program to automate the calculation of the number of neutrons in an atom.

where N is the number of neutrons, A is the atomic mass of the element, Z is the number of protons.

A function to calculate the number of neutrons in C would look like this:

There is a function, but what will it count?

To use this function, we need to declare a huge number of variables with the characteristics of each chemical element without getting confused.

We seem to have automated calculations, but have not gained any advantage in convenience or speed.

It is very inconvenient to enter the parameters of a chemical element every time, then write down the result somewhere, etc..

And so on for another 118 chemical elements.

"It would be great if my favorite language, C, had a mechanism to describe and manipulate complex data," you thought.

Let's visually describe the future structure that will describe any chemical element, for example silicon "Si":

Tudo estava claro?

Seção 1. Capítulo 2
We're sorry to hear that something went wrong. What happened?
some-alt