2019/c++

variables and memory, declaration

fw93 2018. 3. 24. 15:56
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
54
55
56
57
58
59
60
61
62
63
64
65
#include "stdafx.h"
#include <iostream>
#include <cstdio>
#include <vector>
 
using namespace std;
 
class sam {
public:
    int a;
    int b;
    sam(int z, int w) {
        a = z;
        b = w;
    }
};
 
int main2() {
    sam * test = new sam(12);
    return 0;
}
 
struct node {
    int data;
    node * next;
};
 
void append(int data, node * head) {
    node * hello = new node;
    hello->data = data;
    hello->next = NULL;
    node * tmp = head;
    while (tmp->next != NULL) {
        tmp = tmp->next;
    }
    tmp->next = hello;
}
 
void print(node * head) {
    while (head != NULL) {
        cout << head->data << endl;
        head = head->next;
    }
}
 
int main() {
    vector<int> * v1 = new vector<int>;
    vector<int> v2;
    v1->push_back(1);
    v1->push_back(2);
    v1->push_back(3);
    cout << &v1 << " " << &v2 << endl;
    v2 = *v1;
    cout << &v1 << " " << &v2 << endl;
    cout << v2.at(1<< endl;
    while(1){}
    node head = { 1,NULL };
    append(2&head);
    append(3&head);
    append(4&head);
    append(5&head);
    print(&head);
    while (1) {}
    return 0;
}
cs


'2019 > c++' 카테고리의 다른 글

SORTING  (0) 2018.03.26
maps STL  (0) 2018.03.25
list inserts and deletes  (0) 2018.03.24
string manipulations ( pointers )  (0) 2018.03.22
strings(3)  (0) 2018.03.22