-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVectorArray
More file actions
54 lines (46 loc) · 1.62 KB
/
Copy pathVectorArray
File metadata and controls
54 lines (46 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// ConsoleApplication12.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <array>
using namespace std;
int main()
{
/* vector - to tablica dynamiczna, mozna ustalac rozmiar w trakcie trwania programu,
automatycznie przydziela pamieć, */
vector<int> vi; // tablica int o zerowym rozmiarze
int n;
cin>>n;
vector<double> vd(n);
/*array - tablica o stalym rozmiarze( tylko całkowite liczby), pamiec przydzialana na stosie */
array<int,5> ai;
array<double,4> ad = {1.2, 2.1,3.66,3.59};
double a1[4] = {1.2, 2.1,3.66,3.59};
vector<double>a2(4);
a2[0] = 1.0/3.0;
a2[1] = 1.0/5.0;
a2[2] = 1.0/7.0;
a2[3] = 1.0/9.0;
// deklaracja i zainicjalizowanie array
array<double,4> a3 = {3.14, 2.65, 3.56, 1.14};
array<double,4> a4 ;
a4=a3; // dozwolone dla obiektow o tym samym rozmiarze
// mozna odwolywac sie do obiektow indeksowaniem
// array stosuje stos, vector sterta
cout<<"a1[2]: " <<a1[2] << " pod adresem " <<&a1[2]<<endl;
cout<<"a2[2]: " <<a2[2] << " pod adresem " <<&a2[2]<<endl;
cout<<"a3[2]: " <<a3[2] << " pod adresem " <<&a3[2]<<endl;
cout<<"a4[2]: " <<a4[2] << " pod adresem " <<&a4[2]<<endl;
// naduzycie
cout<<"a1[-2]: " <<a1[-2] << " pod adresem " <<&a1[-2]<<endl; //adres zawarty w a1 cofnac sie o 2 elementy i wstawic pokazana wartosc grozi umieszaniem danych poza tablicą
cout<<"a3[2]: " <<a3[2] << " pod adresem " <<&a3[2]<<endl;
cout<<"a4[2]: " <<a4[2] << " pod adresem " <<&a4[2]<<endl;
//metoda at
a2.at(1) =2.3; // przypisuje 2.3 do a2[1]
cin.get();
cin.get();
return 0;
}