Files
freeCodeCamp/guide/portuguese/cplusplus/arrays/index.md
Randell Dawson 0a1eeea424 fix(guide) Replace invalid prism code block names (#35961)
* fix: replace sh with shell

fix replace terminal with shell

fix replace node with js

fix replace output with shell

fix replace cs with csharp

fix replace c++ with cpp

fix replace c# with csharp

fix replace javasctipt with js

fix replace syntax  with js

fix replace unix with shell

fix replace linux with shell

fix replace java 8 with java

fix replace swift4 with swift

fix replace react.js with jsx

fix replace javascriot with js

fix replace javacsript with js

fix replace c++ -  with cpp

fix: corrected various typos

fix: replace Algorithm with nothing

fix: replace xaml with xml

fix: replace solidity with nothing

fix: replace c++ with cpp

fix: replace txt with shell

fix: replace code with json and css

fix: replace console with shell
2019-05-15 19:08:19 +02:00

1.4 KiB
Raw Blame History

title, localeTitle
title localeTitle
C++ Arrays Matrizes C ++

O que são matrizes?

Uma matriz é uma série de elementos do mesmo tipo de dados que são armazenados em locais de memória contígua e podem ser referenciados individualmente.

Por exemplo, uma matriz contendo 5 valores inteiros chamados números é declarada da seguinte forma:

int numbers [5]; 

Inicialização:

//Initialization with entries: 
 int numbers [5] = {1, 2, 3, 4, 5}; 
 
 //Initialization with no values: 
 int numbers [5] = {}; 
 
 //Initialization with declaration: 
 int numbers [] = {1, 2, 3, 4, 5}; 
 //Note that here the number of values defines the size of the array. 
 //In the examples above, the size was fixed beforehand 

Observe que as matrizes em C ++ não são permutáveis em tamanho, o que significa que, uma vez que você tenha declarado uma matriz com tamanho 5, ela não poderá ser ampliada ou diminuída. Caso você realmente precise de uma matriz maior com as mesmas entradas, você teria que copiar todas as entradas para uma nova matriz de tamanho maior.

Acesso:

Elementos de uma matriz podem ser acessados por referência de sua posição na matriz. (Comece a contar de 0).
Exemplo:

x = numbers[0]; // = 1. [0] == first position 
 numbers[2] = 55; // Sets the third position (3) to the new number 55 
 //numbers[] is now: {1, 2, 55, 4, 5}