Documente Academic
Documente Profesional
Documente Cultură
1.5.1. Ex. 1
/* Pointer declaration, using addressing and indirection operators */
int main( ) {
int i = 10, j = 50;
// Pointer declaration
int *iptr;
int main( ) {
int64_t i = 10, j = 50;
// Pointer declaration
_int64 *iptr;
1.5.2. Ex. 2
/* Pointers and cast operator */
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
//#include <bitset>
using namespace std;
int main() {
int n, * pn;
float r, * pr;
pn = &n;
printf("\nThe in memory representation of %d is %x in hex and in bytes: 0x%02x
%02x %02x %02x\n",
n,
n,
*((unsigned char*)pn + 3),
*((unsigned char*)pn + 2),
*((unsigned char*)pn + 1),
*((unsigned char*)pn));
return 0;
}//main
1.5.3. Ex. 3
/* Declaring and making use of different types of pointers */
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
int main( ){
int *pt_int;
float *pt_float;
int i = 10, j = 20;
float x = 1.2345f, y = 32.14f;
void *general; // generic pointer
pt_int = &i;
*pt_int += j;
cout << "The value of i becomes: " << *pt_int << "\n";
general = pt_int;
*(int *)general = 0;
cout << "The last value for i is: " << i << "\n";
pt_float = &x;
y += 5.0f * (*pt_float);
cout << "The value of y is: " << y << "\n";
return 0;
}//main
1.5.4. Ex. 4
/* Passing parameters by value and addresses using functions */
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
int main ( ){
int i = 10, j = 20;