Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

CSC112 Spring 2016 Examples

2370 views
1
#include <iostream>
2
3
using namespace std;
4
5
int
6
main() {
7
int x=1;
8
char c=0xF;
9
double n=16;
10
int *ptr; //pointer to an integer
11
12
//print some stuff out
13
cout << "x: " << sizeof x << endl;
14
cout << "c: " << sizeof c << endl;
15
cout << "n: " << sizeof n << endl;
16
17
//Look at the addresses
18
cout << "x: " << &x << endl;
19
cout << "c: " << (void*)(&c) << endl;
20
cout << "n: " << &n << endl;
21
22
//set ptr to the address of x
23
ptr = &x;
24
25
cout << ptr << endl;
26
cout << *ptr << endl;
27
*ptr = 9;
28
29
cout << x << endl;
30
return 0;
31
}
32
33