i'm getting the segmentation fault at 25th line but i don't understand why?
Are you asking us if you don't understand, or are you telling us you don't understand?
If this causes a segFault, then you are trying to write to a location that is not yours to write to. Whatever the size of the array p is, top is too big. What's the value of top? What size is the array p?
I'm telling that i don't understand?
In the initialize function i already specified top=-1 and in the push function i first incremented top(top++) and then accessed p[top]. please help me with the problem.
but how do i check i running a windows system wherein i don't get a dedicated debugger which shows me value and size of array. i use dev-cpp on win 7. can u help me by checking it on your machine please. or any solution using dev-cpp. and i guess the array is of suitable length. help lease. thanks in advance.
Here's an example of a popular way to determine the value of a variable at a given point. cout << "The value of top right now is " << top << endl;
and i guess the array is of suitable length
That's impossible. That's the whole point. If the segault is on the line you said, you're trying to write outside the array. If the array was of a length suitable to where you're trying to write, everything would be fine.
hello navderm i actually want to learn but i'm very new to pointers and frequently get segmentation faults but those were generally due to accessing null pointers. but this the pointer isn't set to null and i also tries cout statements in the initialize(line 15) as well as push(line 25) code and the top is correctly set to 0 for the first element, and also the size is set 2*len appropriately. I'll try to check it out on gdb but currently not having any linux system with me. Thanks for help @navderm.
Very very thanks ne555 i sorry for doing such mistakes actually i'm newbie and just learning cpp and pointers is my fourth chapter. I'll try reducing globals and optimize the program.
Thanks again for guiding me.