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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:43:55+00:00 2026-05-19T02:43:55+00:00

I have an API taking some options: void init_api(const char* options[][2]); I am allowed

  • 0

I have an API taking some options:

void init_api(const char* options[][2]);

I am allowed to pass a NULL pointer for no options, alternatively, an options array such as this can be passed:

const char* some_options[][2] = { {"opt1", "val1"}, 
                                  {"opt2", "val2"}, 
                                  {0,0} 
                                };

This works without problems:

...
init_api(some_options);
... or ...
init_api(NULL);
...

However, this fails to compile:

const char* my_options[][2] = NULL; // error C2440: 'initializing' : cannot convert from 'int' to 'const char *[][2]'
if(...) {
  my_options = some_options; // error C2440: '=' : cannot convert from 'const char *[4][2]' to 'const char *[][2]'
}
init_api(my_options); // no error here

What is going on here? Can someone explain 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-05-19T02:43:55+00:00Added an answer on May 19, 2026 at 2:43 am

    To declare an empty array of array of pointers to const char, you should use:

    const char* my_options[][2] = {};
    

    You need to declare a pointer to an array of pointers to const char instead. I recommend using a typedef to simplify the syntax.

    typedef const char* array_of_two_cstring[2];
    array_of_two_cstring* my_options = NULL;
    if (...) {
        my_options = some_options;
    }
    init_api(my_options);
    

    In C++ (it is herited from C), array can be implicitly converted to pointer (only once though, that is char[] is compatible with char* but char[][] is compatible with char*[] but not `char**). However, the variable cannot be reassigned. So here you need to use a pointer instead of an array.

    The init_api option accepts NULL as a parameter because for the compiler, its prototype is void init_api(char const* (*)[2]) (the first array degenerated into a pointer), and NULL is a valid pointer.

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

Sidebar

Related Questions

I have an api which takes uni code data as c character array and
We have an API built on Rails, and processing some stuff with resque. After
I have an API call that returns a byte array. I currently stream the
I'm taking some text and want to split it into an array. My goal
I see many Java packages have api, impl and bundle jars (name-api.jar, name-impl.jar, name-bundle.jar).
I have an API that can be implemented by various vendors. I can send
I have an API in the form of a JAR that I would like
I have an API that returns a promise from a deferred object. The problem
I have an API documentation lying around on my Harddrive and to ease my
I have a api app that sits behind a few client facing apps. The

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.