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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:26:44+00:00 2026-06-14T18:26:44+00:00

Suppose I’ve two code samples for creating a integer array of 10 elements: int

  • 0

Suppose I’ve two code samples for creating a integer array of 10 elements:

int *pi = (int*)0; 
realloc(pi,10);

and the other is the one that is written normally, i.e.:

int *pi;
pi= malloc(10*sizeof(int));

Now, my question is: The first type of assignment is legal but not used. Why, although there I may get the starting location of my choice?
Initialization of pointers with constants are legal but not used. Why?

  • 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-14T18:26:45+00:00Added an answer on June 14, 2026 at 6:26 pm

    When NULL is passed, realloc is equivalent to malloc. The NULL call can be useful if you’re re allocating in some kind of loop and don’t want to have a special case the first time you allocate.


    While we’re at it, the fairly standard ways to use malloc and realloc are:

    int* p;
    p = malloc(10 * sizeof(int)); //Note that there's no cast
    //(also, it could just be int* p = malloc(...);)
    
    int* np = realloc(p, 15 * sizeof(int));
    //Note that you keep the old pointer -- this is in case the realloc fails
    

    As a tangential aside: history is the main reason you see declarations and assignments on different lines. In older versions of C, declarations had to come first in functions. That meant that even if your function didn’t use a variable until 20 lines in, you had to declare at the top.

    Since you typically don’t know what the value of a variable not used for another 20 lines should be, you can’t always initialize it to anything meaningful, and thus you’re left with a declaration and no assignment at the top of your function.

    In C99/C11, you do not have to declare variables at the top of scopes. In fact, it’s generally suggested to define variables as close to their use as possible.

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

Sidebar

Related Questions

Suppose that I have the code php as below: <?php include(connectdb.php); $check1 = ;
Suppose you have val docs = List(List(one, two), List(two, three)) where e.g. List(one, two)
Suppose I have an array that looks like this array ([apple] => 1, [dog]=>2,
Suppose I have a pure virtual method in the base interface that returns to
Suppose I have a static method of my class that returns an object of
Suppose we have the name written in any none-latin letters - languages, like Arabic,
Suppose I have a class Baz that inherits from classes Foo and Bar ,
Suppose I have a process that is updating a record and encounters a record
Suppose I have two tables, - emp(empId number(1),empName varchar2(50)) and - manager(manId number(5),managerName varchar2(100))
Suppose I have a data frame, df, that looks like: f t1 t2 t3

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.