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

  • Home
  • SEARCH
  • 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 6609461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:43:14+00:00 2026-05-25T19:43:14+00:00

Can someone please explain to me what’s wrong with the following, and more importantly

  • 0

Can someone please explain to me what’s wrong with the following, and more importantly why?

int main( int argc, char *argv[] )
{
    char array[] = "array";
    char **test;
    test = &array;

    *test[0] = 'Z';

    printf( "%s\n", array );

    return 0;
}

EDIT

My example above was based on a function like this that was crashing:

void apple( char **pp )
{
    *pp = malloc( 123 );
    *pp[0] = 'a'; // technically this is correct but in bad form
    *pp[1] = 'b'; // incorrect but no crash
    *pp[2] = '\0'; // incorrect and crash
}

As pointed out to me by Vaughn Cato although *pp[0] = 'a'; does not crash it is in bad form. The correct form is the parenthesis

void apple( char **pp )
{
    *pp = malloc( 123 );
    (*pp)[0] = 'a'; // correct
    (*pp)[1] = 'b'; // correct
    (*pp)[2] = '\0'; // correct
}

Also as another poster MK pointed out the FAQ covers the difference between arrays and pointers:
http://www.lysator.liu.se/c/c-faq/c-2.html

  • 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-05-25T19:43:15+00:00Added an answer on May 25, 2026 at 7:43 pm

    test = &array

    is wrong because test is of type char** and &array is a char(*)[6] and is a different type from char**

    An array isn’t the same type as char* although C will implicitly convert between an array type and a char* in some contexts, but this isn’t one of them. Basically the expectation that char* is the same as the type of an array (e.g: char[6]) is wrong and therefore the expectation that taking the address of an array will result in a char** is also wrong.

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

Sidebar

Related Questions

Can someone please explain how to obtain this result from the following array? Here
Can someone please explain to me why the output from the following code is
Can someone please explain the difference between ViewState and Session? More specifically, I'd like
Can someone please explain what the following javascript statement is doing? var default_hide =
can someone please explain to me the following JavaScript design pattern example and what
Can someone please explain the difference between the following queries. The joins in the
Can someone please explain the following code? Source: Arrays.class, public static <T> void sort(T[]
Can someone please explain the difference between the following cases and where would we
Can someone please explain to me how to calculate the complexity of the following
Can someone please explain what the & does in the following: class TEST {

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.