COSC 1320 Lecture 4: Pointers

23 views3 pages
POINTERS
#include <iostream>
using namespace std;
int main(){
//declaration
int a; //creates a space in RAM for a
//lets say a has an address called 1195
int *pa; //pa is a variable of type pointer to int
//initialize
a = 10;
inside the red box is 10, the value of a and the address of 10 in the memory is 1195
// Just to know *pa and a are the same thing. *pa = 10, a = 10, pa = address
pa = &a; //pa is equal to address of a, find the address of a and put it into pa
//process
//....
//....
//....
//print
cout << "The value of a is " << a <<endl; //Output 10
cout << "The value of a is " << *pa <<endl;//i want to print the value of where pa points to
//Output 10;
cout << "The address of a is " << pa <<endl;//Output 1195
return 0;
}
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows page 1 of the document.
Unlock all 3 pages and 3 million more documents.

Already have an account? Log in

Get OneClass Notes+

Unlimited access to class notes and textbook notes.

YearlyBest Value
75% OFF
$8 USD/m
Monthly
$30 USD/m
You will be charged $96 USD upfront and auto renewed at the end of each cycle. You may cancel anytime under Payment Settings. For more information, see our Terms and Privacy.
Payments are encrypted using 256-bit SSL. Powered by Stripe.