Hi,
My problem is like the below code. In "pushes" function "ptr++" is increasing 16 bytes
and in "pops" "ptr--" code decreasing only 1 byte as normal. I didnt understand the 16.
Why 16 and 1?
(BC++ 5.5)
Code:#include<iostream.h> #include<stdlib.h> #include<string.h> #include <stdio.h> class stack{ public: stack(); ~stack(); void pushes(char kr); void pops(); private: char* ptr; int tos; }; stack::stack() { tos = 0; ptr = (char*) malloc(sizeof(char)); if (!ptr) { cout << "alloc err\n"; exit(1); } } stack::~stack() { free(ptr); } void stack::pushes(char kr) { ptr = (char*) malloc(sizeof(char)); if (!ptr) { cout << "alloc err\n"; exit(1); } *ptr = kr; tos++; ptr++; // printf("%d\n",ptr); } void stack::pops() { if (tos == 0) { cout << "stack empty\n"; return; } tos--; // printf(" - %d\n",ptr); cout << "pushed [" << tos << "] :" << *ptr << endl; ptr-= 16; } int main() { int i; stack pushpop; pushpop.pushes('A'); pushpop.pushes('B'); pushpop.pushes('C'); for (i = 0; i < 3; i++) { pushpop.pops(); } return 0; }