Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8927017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:07:30+00:00 2026-06-15T08:07:30+00:00

Possible Duplicate: Similarities and differences between arrays and pointers through a practical example I

  • 0

Possible Duplicate:
Similarities and differences between arrays and pointers through a practical example

I used to take them as the same referring to an array name. But now I have encountered an error, that is, when I use int *path and try to access the members of the array, the compiler gets a SIGSEGV(Which I never remembered to have happened in the code I have written before), but I it’s okay when I use int path[].

So why am I getting a SIGSEGV when using int *path ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:07:31+00:00Added an answer on June 15, 2026 at 8:07 am

    Just guessing you are trying to write to an array you have declared in the two possible, not equivalent, ways:

        int *path = { 4, 5, 3, -1}; /* you're saying this does not work ... when? */
     //  ^ compiler "warning" (error) expected, see edit below
        path[2] = 1;                /* .. when you try this */
    

    but

        int path[] = { 4, 5, 3, -1};
        path[2] = 1;                 /* but this works */     
    

    In the first case, path is a pointer to a “static” “list” put somewhere. You have just the pointer to it, can read the content, but likely if you try to write on it, you have segmentation fault. (Likely since those data could be in a memory you can write to even if often it happens you can’t, but it depends on the system).

    In the second case, an area on the stack is reserved, big enough to hold the data, which then are copied into that area. In this case, you can both read and write to it.

    edit

    as noticed in comments the first example gives warning, you will need a cast (int []) to compile without warning. Then, let us suppose the array is created somewhere where you can’t write to, though it could not be the case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What are the similarities and differences between Java Annotations and C# Attributes?
Possible Duplicate: Java's Interface and Haskell's type class: differences and similarities? When I started
Possible Duplicate: Reading through file using ifstream I'm trying to find a way to
Possible Duplicate: Difference Between Equals and == in which cases equals() works exactly like
Possible Duplicate: array_splice() for associative arrays How to add an array value to the
Possible Duplicate: What is the difference between a function expression vs declaration in JavaScript?
Possible Duplicate: Cyclic module dependencies and relative imports in Python Consider the following example
Possible Duplicate: Matching an integer between the brackets What is the regex for matching
Possible Duplicate: Singleton: How should it be used Following on from Ewan Makepeace 's
Possible Duplicate: How do I make a request using HTTP basic authentication with PHP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.