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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:03:46+00:00 2026-05-23T05:03:46+00:00

I declared an array and take input from user. Now i want to check

  • 0

I declared an array and take input from user. Now i want to check duplicate entries, they have to be deleted and memory should be freed. Is it possible to free memory.

freeing the unused memory and reducing the array size?

I entered [10,21,3,4,4,2,6,7,21,4,10].it should get truncated as [10,21,3,4,2,6,7] and array length should now be 7,and i don’t want to use sorting.

  • 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-05-23T05:03:46+00:00Added an answer on May 23, 2026 at 5:03 am

    I declared an array of length 100 and took input from user

    so you mean like this:

        int input[100];
    /* - ask 100 input from user */
    

    Is it possible to free memory

    the answer is no because you statically allocate 100 integers.

    If you want to be able to reduce memory then you should do something like this:

    int *tempBuffer=malloc(100*sizeof(int)); /* dynamic allocation */
    
    for(i=0;i<100;++i) scanf("%d",&tempBuffer[i]);/* - ask 100 input from user */
    
    int uniqueN=10   /* - assume the first 10 entries are the unique entries */
    
    int *realBuffer=malloc(uniqueN*sizeof(int)); /* - allocate new buffer just enough for the unique entries */
    
    for(i=0;i<uniqueN;++i) realBuffer[i]=tempBuffer[i];  /* - copy the unique entries from input to the final buffer */
    
    free(tempBuffer);  /* - tempBuffer is now unused, free it */
    
    /* here we have realBuffer with just enough size, no unused memory */
    

    Another solution is to realloc tempBuffer after arranging the first uniqueN entries to be the unique entries:

    realloc(tempBuffer,uniqueN);
    

    don’t forget to check if malloc or realloc returns NULL

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

Sidebar

Related Questions

lets say that a user want to take vacation from 17-10-2010 to 15-11-2010. on
I'm trying to build a hash from an array. Basically I want to take
I have declared an array in the form: var refs = { 'EE810': Presence
I have a C++ array declared as mentioned below: CString carray[] = { A,
I have a simple function in which an array is declared with size depending
I have a variable declared like this in a class: Entity *array[BOARD_SIZE][BOARD_SIZE]; I need
I have an byte array declared in the header of the class. When I
If I have an array declared like this: int a[3][2]; stored at address A
I'm localizing a menu and I want to assign a declared array to an
I want to pass in an array of parameters to SQLBindParameters, and have this

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.