-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
120 lines (91 loc) · 2.66 KB
/
main.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <iostream>
#include<conio.h>
#include<stdlib.h>
using namespace std;
int main()
{
cout << "Trabajando con punteros y referencias" << endl;
//accederemos a la dirección de memoria de una variable
int a=10;
int *p=&a;
cout <<"Contenido de la variable"<<a<<endl;
cout <<"Dirección de memoria de la variable"<<&a<<endl;
cout <<"Contenido de memoria del puntero"<<p<<endl;
cout <<"Dirección de memoria del puntero"<<&p<<endl;
cout <<"Modificaremos el valor de a desde puntero"<<endl;
cout <<"El valor de a desde p: "<<*p<<endl;
*p=1000;
cout <<"El valor de a es: "<<a<<endl;
cout <<"==================="<<endl;
cout <<"Haremos una referencia a la misma memoria"<<endl;
int &r=a;
cout <<"Contenido de la variable"<<a<<endl;
cout <<"Dirección de memoria de la variable"<<&a<<endl;
cout <<"Contenido de la referencia"<<r<<endl;
cout <<"Dirección de memoria de la referencia"<<&r<<endl;
/*
cout<<"Trabajando con punteros: par o impar"<<endl;
int numero,*pn;
cout<<"Cual es tu numero:"; cin>>numero;
pn=№
if(*pn%2==0)
{cout<<"Es numero "<<*pn<<"es par"<<endl;
cout<<"Posición de memoria"<<pn<<endl;
}
else
{cout<<"Es numero "<<*pn<<"es impar"<<endl;
cout<<"Posición de memoria"<<pn<<endl;
}
*/
/*
int numero,*pn,c=0;
char salir='n';
while(salir!='y')
{
cout<<"Trabajando con numeros primos"<<endl;
cout<<"Proporciona un numero:"<<endl;
cin>>numero;
pn=№
for(int i=1; i<*pn; i++)
{
if(*pn%i==0)
c++;
}
if(c==2)
cout<<"es un numero primo"<<endl;
else
cout<<"no es un numero primo";
cout<<"deseas salir?(y/n):";
cin>>salir;
}
getch();*/
/*
cout<<"Arreglos y punteros"<<endl;
int n[]={10,20,30,40,50};
int *np;
np=n; // se copia la direccion de memoria del espacio 1 del arreglo
for(int i=0;i<5;i++)
{
cout<<"Elemento:"<<i<<":"<<*np++<<endl;
}
*/
cout<<"Arreglos y numeros pares"<<endl;
int n[15],*np;
for(int i=0; i<15; i++)
{
n[i]=rand()%100+1;
}
np=n;
for(int i=0;i<15;i++)
{
if(*np%2==0){
cout<<"n: "<<n[i]<<" es par: "<<*np<<"su posición en memoria es: "<<np<<endl;
}
else{
cout<<"Es impar"<<endl;
}
*np++;
}
getch();
return 0;
}