Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 13.59.183.186
Web Server : Apache
System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64
User : apache ( 48)
PHP Version : 7.2.24
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0705) :  /home/jcwhiley/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/jcwhiley/pointer1.cpp
//
//	p. 174 pointer type
//


#include <iostream>
using namespace std;

int main()
{
	int x = 42;
	float num = 1.1;
	char ch = 'A';
	string str = "Hi";

// Declare Integer Pointer
// The value of the variable to what is pointing to
	int* ptr;
// ptr points to x?
	ptr = &x;

	char* q = &ch;
// Address string type
	string* spr = str&
	
	cout << "Address of x: " << &x << " " << ptr << "\n";
	cout << "Address of q: " << q << "\n";
	cout << "Address of spr: " << spr << "\n";
//________________________________________________
//  Given char* cptr;
//  and char ch = 'H';
//  How do we make cptr point to 'H'?
// (ANS) cptr = &ch;

// char* p means that p is a char pointer, and so on...
// p = q means whatever value q has will also be the value of p.

// Whenever we have assignments like this, all values are equivalent.
//________________________________________________
// Dereference
	cout << *ptr << "\n" << *q << "\n";
	// 42
	// A
        cout << *ptr << "\t" << x << "\n";
// Change 42 to 55.
	*ptr = 55;
	cout << *ptr << "\t" << x << "\n";

	return 0;
}


Stv3n404 - 2023