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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:48:23+00:00 2026-06-14T03:48:23+00:00

I’m sure this has been asked before, but a cursory google and stack overflow

  • 0

I’m sure this has been asked before, but a cursory google and stack overflow search didn’t turn up the answer.

#include <stdio.h>

int main() {
    char a[128][1024];
    strcpy(a[0], "hello");
    strcpy(a[1], "foo");
    strcpy(a[2], "bar");
    char **b = a;
    printf("%s\n", a[0]); //same as printf("%s\n", a)
    printf("%s\n", a[2]+1); //print from 2nd char of 3rd string
    printf("%s\n", b); //same as printf("%s\n", a), makes sense
    printf("%s\n", b[0]); //segfault???
}

First off, why is the last one a segfault? I’d expect same behavior as array a. How would I access the n-th string from b in a generalized way? What are the differences in treatment between a and b?

On a similar note, the way I understand it, a[n] is syntactic sugar for *(a+n). Is this correct, both for pointers and for arrays? Yet it seems getting different behavior for a and b.

Thanks!

  • 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-14T03:48:24+00:00Added an answer on June 14, 2026 at 3:48 am

    char **b says “At the place where b points, b[0], there is a pointer to a char. And, if I use b[1], b[2],…, those are also pointers to char.”

    In contrast char a[128][1024] says “a is 128 arrays of 1024 char.” When you do this, at the place where a is, there are no pointers. There are just char. In memory, it looks like 131,072 char in a row (128•1024 = 131,072).

    When you assign char **b = a, assuming the compiler allows you to, you set b to be the address of a. When you use b[0], there should be a pointer there. But there is not. There are just char there. When you pass b[0] to printf, the compiler goes to where b points, loads several bytes as if they were a pointer, and passes the resulting value to printf. Then printf crashes, because the bytes point to some bad location.

    A proper definition of b would be char (*b)[1024] = a;.

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

Sidebar

Related Questions

This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to count how many characters a certain string has in PHP, but
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the 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.