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 9291721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:42:56+00:00 2026-06-18T20:42:56+00:00

// Whenever i am increasing function call times of push more than 8, it

  • 0

// Whenever i am increasing function call times of push more than 8, it get crashed before that everything is working good. your help is required. In the below code i have created a program for stack using Dynamic array keeping in mind there should not be any stack overflow by using realloc function to doubling the values whenever the stack gets filled.

#include<stdio.h>
#include<stdlib.h>
#include<memory.h>
typedef struct ArrayStack
{
int top;
int capacity;
int *arr;
}*stack;

stack Creation()
{
 stack S;
 S=(stack)malloc(sizeof(struct ArrayStack));
 if(!S)return NULL;
 S->top=-1;
 S->capacity=1;
 S->arr=(int*)malloc(S->capacity*sizeof(int));
 if(!S->arr)return NULL;
 return S;
}
int is_Full(stack S)
{
return S->top==S->capacity-1;
}
int is_Empty(stack S)
{
return S->top==-1;
}

void Doubling(stack S)
{
 S->capacity*=2;
 S->arr=realloc(S->arr,S->capacity);
}

void push(stack S,int data)
{
if(is_Full(S)) 
Doubling(S);

S->arr[++S->top]=data;
}

int pop(stack S)
{
if(is_Empty(S))
printf("\nStack underflow");
else
return S->arr[S->top--];
}

int main()
{
stack S;
int i=0,size=9;
S=Creation();
**for(i=0;i<size;i++)
push(S,19+1);**   // As in this case

return 0;
}
  • 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-18T20:42:57+00:00Added an answer on June 18, 2026 at 8:42 pm
    S->arr = malloc(S->capacity * sizeof(int));
    S->arr = realloc(S->arr, S->capacity);
    

    You only reallocate enough space for S->capacity / sizeof(int) items.

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

Sidebar

Related Questions

Whenever I try to run this function in Chromium, I get the error message
Whenever I try installing anything using gem, I get this error - murtaza@murtaza-dev:~$ sudo
Whenever I close XCode, the User Info entries that I set for attributes in
Whenever the activity that initiates the scan happens, the android application force closes. It
Whenever I try and gem install cocoapods I get an error Basil-MBP:Magic8Ball Basil$ gem
Whenever I have some records/objects that I want to be in a certain order,
Whenever I use the revert changes from this revision function in Tortoise SVN, then
I get a timeout exception whenever trying to connect to my selfhosted wcf. This
Whenever I save a model with a mounted uploader, the versions get deleted whenever
Whenever I create an init that has a delegate conforming to a protocol I

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.