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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:36:58+00:00 2026-05-13T11:36:58+00:00

How to find the size of a predefined char[] variable that holds a string?

  • 0
  1. How to find the size of a predefined char[] variable that holds a string?
    Should sizeof be enough?
    I don’t want to use strlen() since a ‘\0’ character may occur in the string, and for optimization reasons.
    E.g.: char str[] = "Hello \x45\x10\x00 World!";

  2. What do you do when there’re initials in the identifier? E.g. GetURLParameters().
    I thought of adding an underscore: GetURL_Parameters(). What is the convention for this situation?

  3. How can I easily copy values to the fields of a struct that is pointed by a variable/pointer?
    For example, I would like to do something similar to:

    struct {
    int         bar1;
    char*       bar2;
    callback    bar3;
    } *foo = NULL;
    foo = malloc(sizeof *foo);
    *foo = { 0, "Hello World!", myFunc };   // This is wrong
    
  4. Why programmers sometimes use an ampersand to assign an address of a function to a function pointer? E.g.:

    void (*callback)(void);
    callback = &myFunc;

    (Sorry, but I can’t edit well my post. It looks different when I edit, and when it’s shown to you)

  • 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-13T11:36:59+00:00Added an answer on May 13, 2026 at 11:36 am
    1. If it’s a char[] and not a char *, sizeof() will give you the array size (which is strlen() + 1 for nul-terminated strings). If you need to work extensively with strings (especially ones that may have the '\0' character in them and/or may not be nul-terminated) you should consider using a string library. It will make your life much easier.
    2. Whatever you want. I personally never use capital letters in identifiers, because I think MixedCaseIdentifiers are ugly. There is no convention for naming identifiers, only conventions that some people like. Use whatever looks best to you (and your team).
    3. You can do this:

      struct s {
          int         bar1;
          char*       bar2;
          callback    bar3;
      };
      struct s *foo = NULL;
      static struct s default = { 0, "Hello, world!", myFunc };
      foo = malloc(sizeof *foo);
      *foo = s;
      

      My standards-fu is failing me, so I’m not sure why this works (or even if it does absolutely) but I believe it does. If it doesn’t work, you just need to make an init function that sets all the fields to their default values.

    4. Consistency. When assigning an address to a pointer, it’s normally necessary, i.e. int i = 5, *j = &i; so even though it’s not strictly necessary for function pointers, some people like to do it so that all pointer assignments look the same. It’s just aesthetics.

    However, in the future, most of these questions are unrelated to each other. You shouldn’t group four unrelated questions into one giant monster question, but instead ask them separately. It’ll make you take more time for each one, and each will come out more coherently so we’ll be able to give you better answers (and you’ll learn more).

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

Sidebar

Related Questions

Is there a way to find the size of a file object that is
How to find out size of session in ASP.NET from web application?
How can I find out the size of a file I opened with an
If i need to find out the size of a tcp packet on BSD.....what
I'm trying to find the file size of a file on a server. The
Is there a way to find out the size of a SQL Server database
How do you find out the length/size of the data in an ntext column
I find myself defining classes like: struct AngleSize { explicit AngleSize(double radians) : size(radians)
Is there a way to find out what the total size of the unextracted
I am trying to find out programatically the max permgen and max heap size

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.