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 7722727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:15:30+00:00 2026-06-01T04:15:30+00:00

I am lost. I cannot assign an int to a dereferenced int * .

  • 0

I am lost. I cannot assign an int to a dereferenced int *.

  printf("in octave\n");

  int *default_octave;
  printf("attr[%d]: %s\n",i+1,attr[i+1]);

  const char *octave_char = attr[i+1];
  printf("octave_char: %s\n", octave_char);

  int octave_number = atoi(octave_char);
  printf("octave_number: %d\n", octave_number);
  fflush(stdout);

  *default_octave=octave_number;
  printf("in octave pt 2\n");
  fflush(stdout);

This is the output:

in octave
attr[1]: 4
octave_char: 4
octave_number: 4
Segmentation fault

Why?

Running the GDB debugger gets to that line and then seg faults, too.

4

0            int octave_number = atoi(octave_char);
(gdb) s
41            printf("octave_number: %d\n", octave_number);
(gdb)
octave_number: 4
42            fflush(stdout);
(gdb)
43            *default_octave=octave_number;
(gdb) print octave_number
$1 = 4
(gdb) s

Program received signal SIGSEGV, Segmentation fault.
0x0000000000400a7b in parse_song (song_data=0x7fffffffe7a8, attr=0x602600) at nullaby.c:43
43            *default_octave=octave_number;
(gdb)

I have no idea what I can do to fix this.

  • 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-01T04:15:33+00:00Added an answer on June 1, 2026 at 4:15 am

    You have an int pointer. Right.

    It just mean you have a variable pointing to some memory area.
    But you haven’t allocated/reserved that memory area. So it can point to anything.

    And it will surely point to a memory area you don’t own, hence the segmentation fault.

    You need to allocate memory for the pointer…

    For instance:

     int * default_octave = malloc( sizeof( int ) );
    

    Or you may also use:

    int   default_octave_val;
    int * default_octave = &default_octave_val;
    

    Either you allocate memory to store your int (and then get a pointer to a valid memory area), or you create a pointer to an existing memory area (in the given example, a stack address).

    Then you can de-reference that pointer, as it points to a valid memory area.
    If it don’t, you’ll have a segmentation fault, or a bus error, depending on your OS.

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

Sidebar

Related Questions

I lost my .ui file, and it seems pyuic4 cannot make a .ui file
I feel lost with the Regex Unicode Properties presented by RegexBuddy, I cannot distinguish
I'm lost on this one. I receive a TypeError: Error #1009: Cannot access a
I lost my last commit because I accidentally ran git reset --hard HEAD^. Note:
I am a bit lost as to how to explain this, so I will
I'm a bit lost with Subversion (1.5+) here: I modified the trunk in my
I have lost my private key for iPhone Distribution Certificate during an OS upgrade.
I'm kind of lost in between UIImage, UIImageView, CG, layers... I want to draw
I've lost the toolbar on my DataFormWebPart that has the dropdown boxes that apply
I'm a bit lost, one of my developer co-worker is doing a drupal website,

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.