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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:54:14+00:00 2026-05-26T17:54:14+00:00

I declare the following array: char* array [2] = { One, Two}; I pass

  • 0

I declare the following array:

char* array [2] = { "One", "Two"};

I pass this array to a function. How can I find the length of this array in the function?

  • 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-26T17:54:15+00:00Added an answer on May 26, 2026 at 5:54 pm

    You can’t find the length of an array after you pass it to a function without extra effort. You’ll need to:

    1. Use a container that stores the size, such as vector (recommended).
    2. Pass the size along with it. This will probably require the least modification to your existing code and be the quickest fix.
    3. Use a sentinel value, like C strings do1. This makes finding the length of the array a linear time operation and if you forget the sentinel value your program will likely crash. This is the worst way to do it for most situations.
    4. Use templating to deduct the size of the array as you pass it. You can read about it here: How does this Array Size Template Work?

    1 In case you were wondering, most people regret the fact that C strings work this way.

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

Sidebar

Related Questions

can we declare a function in a header file in following way? extern int
The following are the two ways of initializing a char array: char charArray1[] =
Can you help me out with this question please. Question: Given the following array
If I declare the following variables: int array[10] = { 34, 43,12, 67, 34,
I have the following program. However, I can't understand why I have to pass
I have the following code where I declare a PHP array variable and inside
I understand how to pass an array to a function and let that function
When I pass an array into a function in a dynamic library with the
I want to know how to declare a two dimensional array in Python. arr
Given the following: declare @a table ( pkid int, value int ) declare @b

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.