logo

Crowdly

The following program has a memory allocation issue. At which loop index will o...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

The following program has a memory allocation issue. At which loop index will our program generate a segmentation fault?

#include <stdlib.h>

#include <stdio.h>

int main(int argc, char ** argv) {

  char *name;

  long long i;

  name = (char *) (malloc (20 * sizeof (char)));

  for(i=0; i>-1; i++) {

    name[i] = (char)i;

    printf("i=%lld\n", i);

  }

 

}

0%
0%
0%
0%
More questions like this

Want instant access to all verified answers on moodle.eurecom.fr?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!