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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:18:49+00:00 2026-06-13T10:18:49+00:00

What exactly does this code fragment do? #include <stdio.h> List *makeList(int n) { List

  • 0

What exactly does this code fragment do?

#include <stdio.h>
 List *makeList(int n) { 
    List *l, *l1 = NULL; 
    for (int i = 0; i < n; i++) {
        l = malloc(sizeof(List)); 
        l->val  = n-i;
        l->next = l1;
        l1 = l;
    }
    return l;
}

My notes say that “Given a number n,
build a list of length n where
the ith element of the list
contains i”

But I don’t get that…

  • 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-13T10:18:50+00:00Added an answer on June 13, 2026 at 10:18 am

    The tricky thing here is that the list is built backwards, note that each element’s value is set to n - i, and i counts from 0 to n - 1. So, the first element will get value n, the next one will get n - 1, and so on.

    This is probably done in order to save on a variable (!); otherwise it would be required to have another pointer to remember the first node, in order to have something to return.

    Also, it doesn’t check the return value of malloc(), which is always scary.

    For n = 0, it will return an undefined value (the value of l), which is really scary.

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

Sidebar

Related Questions

I found this code on a hacked site, what does it do exactly? It
I would like to know what this code does exactly. - (void)dialogDidSucceed:(FBDialog*)dialog { //[self
Why 'exactly' does this code loop endlessly if you enter a non number character?
Can anyone tell me what exactly does this Java code do? SecureRandom random =
Miner::Miner(int id):BaseGameEntity(id), m_Location(shack), m_iGoldCarried(0), m_iMoneyInBank(0), m_iThirst(0), m_iFatigue(0), m_pCurrentState(GoHomeAndSleepTilRested::Instance()) What exactly does this mean? It
I was wondering how exactly does TCP implement in-order delivery. lets say this is
I found this jquery plugin which does exactly what I need, but I want
I found this tutorial which pretty much does exactly what I want: http://webstutorial.com/jquery-popup-jquery-slide-popup/jquery Except
I found some information about this on Scott Hanselmans Blog Does anybody exactly know
Does anyone know exactly how this value is derived? For half our team it

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.