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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:31:55+00:00 2026-06-03T08:31:55+00:00

I know this question asked many times and I’m not asking how to do

  • 0

I know this question asked many times and I’m not asking how to do it because i did that at compile-time. My question is how it works because that is what i don’t understand.

When passing a char[] to a function it looses its information and become char* and because of that we can not get size of character array at compile time using template, so i tried and passed the string itself and it worked:

template <int N> inline int arr_len(const char (&)[N]) { return N - 1; }

#define STR "this is an example!"

const char *str_ptr = STR;

int main()
{
  int array_size = arr_len(STR);
}

I tested this code with VC++ 2008, Intel C++ 12 and GCC 4.7 and it works.

By passing the string itself the compiler sees it as const char[] – at least that what i think – and he able to get the string size, How is that possible?

  • 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-03T08:31:56+00:00Added an answer on June 3, 2026 at 8:31 am

    String literal type is an array, not a pointer. So, when you pass it directly to a function that takes array by reference, it doesn’t decay to a pointer.

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

Sidebar

Related Questions

i know that this is a famous question and have been asked many times.
I know this is a question that has been asked many times before, but
I know this question was asked many times, but still my problem is not
I know that this question has been asked many times before in different guises
Hey all, I know that this question has been asked many times in this
I know this question has been asked many times, but I have not been
I know that this question has a been asked many times, but I still
i know this is an old question, asked many times. but i am not
I know that this question had been asked many times, but every answer seems
I know this question has been asked many times. I've response string that contains

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.