/*
It's not easily readable or some-what explicitly
'cause comments are lack, goal is not clear
Prctice is the sole criterion of truth
so just read the following blocks of code is not enough
practice is also an important part of programming
*/
#include <iostream>
#include <cstring>
char * getname(void);
using namespace std;
struct car{
char name[10];
int num;
char* series[50];
};
car mine = {"Volvo", 1, "good"};
car * p2m = &mine;
int main(void) {
double wages[3] = {10.2, 12.3, 12.5};
short stacks[3] = {2, 5, 7};
double* pw = wages;
short* ps = &stacks[0];
for(int i=0;i<2;i++){
pw++; ps++;
cout << pw << " "<< *pw << endl;
cout << ps << " "<< *ps << endl;
cout << sizeof(wages) << endl;
cout << sizeof(pw) << endl;
cout << sizeof(stacks) << endl;
cout << sizeof(ps) << endl;
cout << stacks << " " << stacks[i] << " " << *stacks << " " << *(stacks + 1) << endl;
cout << wages << " " << wages[i] << " " << *wages << " " << *(wages +1) << endl << endl;
}
int a = 3;
int* b = &a;
cout << &a << " " << a
<< " " << *b << " " << b << endl;
int size;
cin >> size;
// int* pz = new int[size];
int* pz = new int; *pz = size; *(pz+1) = 99;
cout << pz << " " << *pz << " " << * (pz+1) << endl;
delete [] pz;
cout << pz << " " << *pz << " " << *(pz + 1) << endl;
const char* pro = "VIP";
char* p2a;
char animal[20];
// cin >> ps;
cin >>animal;
p2a = animal;
cout << pro << " " << *pro << " " << p2a << " " << *p2a << endl;
char * name;
name = getname();
cout << name << " at " << (int*)name << " " << sizeof(name) << " " << *name << endl;//if we run the program, we'll found that we have conserved some memories while storing data
delete [] name;
//struct
cout << (*p2m).name << endl << (*p2m).num << endl << *(*p2m).series << endl;
return 0;
}
char * getname(void){
char temp[80];
cout << "ENTER:\n";
cin >> temp;
cout << "before changing " << temp << " " << &temp << " " << sizeof(temp) << endl;
char * pn = new char[strlen(temp)+1];
strcpy(pn, temp);
return pn;
}