Segmentation fault (core dumped)

Source: Internet
Author: User
Tags printf

The following program accidentally writes Parr as a *parr in 11 rows scanf (), which is not a problem at compile time, but appears at run time:

[Lujinhong@lujinhong chapter12]$ gcc reverse3.c
[Lujinhong@lujinhong chapter12]$./a.out
Enter number:19 76 8 93 766 8 6 934 0-3
Segmentation fault (core dumped)


#include <stdio.h>

#define ARRAY_SIZE

int main (void) {

    int arr[array_size], *parr;

    printf ("Enter%d number  :", array_size);
    for (Parr=arr; parr<arr+array_size; parr++) {
        scanf ("%d", *parr);
    }

    printf ("The number would output in reversal order:\n");
    for (parr=arr+array_size-1; parr>=arr; parr--) {
        printf ("%d\t", *parr);
    }
    printf ("\ n");

    return 0;

Segmentation fault (core dumped) is generally caused by improper memory operation, and it is common to:

(1) The array is out of range.

(2) Read-only memory has been modified.

(3) This example also modifies the read-only memory.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.