Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8539885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:28:23+00:00 2026-06-11T11:28:23+00:00

From all the sources I’ve read, they say – the difference between peek and

  • 0

From all the sources I’ve read, they say – the difference between peek and pop is that peek doesn’t remove the top value.
In the provided example from my lecture notes, apparently they do the same using a different method of subtraction. After both operations top has 1 subtracted.

Am I right?
Probably not, can somebody explain how do those differ?

int pop(void)
{
    assert(top>0);
    return data[--top];
}
int peek(void)
{
    assert(top>0);
    return data[top-1];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:28:24+00:00Added an answer on June 11, 2026 at 11:28 am

    top is a state variable for your stack, and in this case it is a stack which is stored in a regular array. The variable top references the top of the stack by storing an array index.

    The first operation, pop, uses the decrement operator to change the variable top. --top is equivalent to top = top - 1. And hence after a call to pop the state of the stack is also changed. The old value will remain in the array, but since the variable top now references a different index, this value is effectively removed: the top of the stack is now a different element. Now if you call a push, this popped value will be overwritten.

    The second operation doesn’t change the value of the variable top, it only uses it to return the value at the top of the stack. The variable top still references the same value as the stack’s top, and so the stack is unchanged.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to convert tons of pictures, coming from all kinds of sources, in
How to remove all inline styled style=properties+val from every tag from a long source
I'm developing a java servlet web application that manages information from multiple databases (all
I'm trying to D-n-D items from View to another View or Panel. All sources
I am importing via RSS various news articles from various sources (all beyond my
I'm really confused by all the ambiguity from all the sources I've been looking
I know how to generate my Localizable.strings file from all the source (*.m) files
What all possible support is there from open source world for building web based
If I modify the source ip address of all outgoing ip packets from my
I am trying to copy all format file (.txt,.pdf,.doc ...) file from source folder

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.