Forums Programming Assignment Help Explain the meaning of Segmentation violation

This topic contains 1 reply, has 2 voices, and was last updated by  ahprofessional 6 years, 2 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #15170

    Aakanksha
    Participant

    Explain the meaning of “Segmentation violation”.

    #15171

    ahprofessional
    Participant

    Segmentation violation usually occurs at the time of a program’s attempt for accessing memory location, which is not allowed to access. The following code should create segmentation violation.
    main() {
    char *hello = “Hello World”;
    *hello = ‘h’;
    }
    At the time of compiling the program, the string “hello world” is placed in the binary mark of the program which is read-only marked. When loading, the compiler places the string along with other constants in the read-only segment of the memory. While executing a variable *hello is set to point the character ‘h’ , is attempted to write the character ‘h’ into the memory, which cause the segmentation violation. And, compiler does not check for assigning read only locations at compile time.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.