A
A
Andrey Titov2016-11-14 21:34:04
Programming
Andrey Titov, 2016-11-14 21:34:04

What is "Segmentation error (memory dumped)"?

The program compiles, but at startup it gives a message -
Segmentation error (dumped memory)

#include <stdio.h>
#include <stdlib.h>

void number_printer(int number);

int main(int argc, char **argv)
{
  int num = atoi(argv[1]);
  number_printer(num);
  return 0;
}

void number_printer (int number)
{
    int num;
    printf("Enter number: ");
    scanf("%d ", &num);
    switch(num){
        case 0: printf("Zero, ");
        break;
        case 1: printf("One, ");
        break;
        case 2: printf("Two, ");
        break;
        case 3: printf("Three, ");
        break;
        default: printf("%d ", num);
        break;
    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2016-11-14
@Rsa97

The program tried to access data in an inaccessible memory segment. Error in call
printf("%d ", num);

S
SagePtr, 2016-11-14
@SagePtr

99% that you are accessing a null pointer.
And most likely here:
int num = atoi(argv[1]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question