Forums Programming Assignment Help Explain the meaning of Segmentation violation

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

    Explain the meaning of “Segmentation violation”.


    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.