-
Notifications
You must be signed in to change notification settings - Fork 0
/
punteiro.cpp
66 lines (56 loc) · 1.22 KB
/
punteiro.cpp
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
66
#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
int vector[3] = {1, 2, 3};
int **p; //
int **pc;
//calloc aloca e limpa mas a sintaxis eh um pouco diferente
//malloc aloca memoria sem limpar
p = (int **) malloc(3 * sizeof(int*));
pc = (int **) calloc(3, sizeof(int*));
//p = int **(malloc(3 * sizeof(int*))); //didn't work
cout<<"sizeof(sizeof())=" << sizeof(sizeof(int*))<<endl;
cout<<"sizeof()="<< sizeof(int*)<<endl;
for(int i=0; i<3; i++)
{
p[i] = (int*) malloc(4*sizeof(int));
pc[i] = (int*) calloc(4, sizeof(int));
//p[i] = int*(malloc(4*sizeof(int))); //didn't work
}
cout<<"p"<<endl;
for(int i=0; i<3; i++)
{
cout<<"| ";
for(int j=0; j<4; j++)
{
//p[i][j] = 10*(i+1) + j+1;
cout<<p[i][j]<<"\t\t";
}
cout<<"|"<<endl;
}
cout<<"pc"<<endl;
for(int i=0; i<3; i++)
{
cout<<"| ";
for(int j=0; j<4; j++)
{
cout<<pc[i][j]<<" ";
pc[i][j] = 10*(i+1) + j+1;
}
cout<<"|"<<endl;
}
cout<<"pc"<<endl;
for(int i=0; i<3; i++)
{
cout<<"| ";
for(int j=0; j<4; j++)
{
cout<<pc[i][j]<<" ";
//p[i][j] = 10*(i+1) + j+1;
}
cout<<"|"<<endl;
}
return 0;
}