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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:11:02+00:00 2026-05-21T21:11:02+00:00

Consider the following. Why does sizeof return 23? And how can I get the

  • 0

Consider the following. Why does sizeof return “23”? And how can I get the real size? (without counting heh)

char defaultsettings[] = "<?xml version=\"1.0\"?>\n";
strcat(defaultsettings, "<CsSettings>\n<options>\n");
strcat(defaultsettings, "<spin name=\"maxTries\" value=\"1000\" />\n");
strcat(defaultsettings, "<spin name=\"rollCount\" value=\"1\" />\n");
strcat(defaultsettings, "<check name=\"matchItems\" value=\"1\" />\n");
strcat(defaultsettings, "<check name=\"highlightItems\" value=\"1\" />\n");
strcat(defaultsettings, "<check name=\"buyListMode\" value=\"0\" />\n");
strcat(defaultsettings, "<radio name=\"matchItemType\" value=\"0\" />\n");
strcat(defaultsettings, "<check name=\"matchLocations\" value=\"0\" />\n");
strcat(defaultsettings, "<check name=\"highlightLocations\" value=\"1\" />\n");
strcat(defaultsettings, "<check name=\"allMissionsSameLocation\" value=\"0\" />\n");
strcat(defaultsettings, "<check name=\"highlightFind\" value=\"0\" />\n");
strcat(defaultsettings, "<check name=\"highlightReturn\" value=\"0\" />\n");
strcat(defaultsettings, "<check name=\"highlightRepair\" value=\"0\" />\n");
strcat(defaultsettings, "<check name=\"highlightPerson\" value=\"0\" />\n");
strcat(defaultsettings, "<check name=\"highlightKill\" value=\"0\" />\n");
strcat(defaultsettings, "<check name=\"ignoreFind\" value=\"0\" />\n");
strcat(defaultsettings, "<check name=\"ignoreReturn\" value=\"0\" />\n");
strcat(defaultsettings, "<check name=\"ignoreRepair\" value=\"0\" />\n");
strcat(defaultsettings, "<check name=\"ignorePerson\" value=\"0\" />\n");
strcat(defaultsettings, "<check name=\"ignoreKill\" value=\"1\" />\n");
strcat(defaultsettings, "<combo name=\"itemValueBase\" value=\"1\" />\n");
strcat(defaultsettings, "<check name=\"matchMissionValue\" value=\"0\" />\n");
strcat(defaultsettings, "<spin name=\"matchMissionMinValue\" value=\"10000\" />\n");
strcat(defaultsettings, "<check name=\"levelCalcFixerMode\" value=\"0\" />\n");
strcat(defaultsettings, "<spin name=\"bneBonus\" value=\"1\" />\n");
strcat(defaultsettings, "<spin name=\"levelCalc\" value=\"1\" />\n");
strcat(defaultsettings, "<spin name=\"missionCalc\" value=\"1\" />\n");
strcat(defaultsettings, "<check name=\"log\" value=\"0\" />\n");
strcat(defaultsettings, "<entry name=\"useKey\" value=\"e\" />\n");
strcat(defaultsettings, "</options>\n<items>\n</items>\n");
strcat(defaultsettings, "<locations>\n<location>\n<string>Milky way</string>\n");
strcat(defaultsettings, "<x>\n<var>3050</var>\n<var>3400</var>\n</x>\n");
strcat(defaultsettings, "<y>\n<var>1000</var>\n<var>1200</var>\n</y>\n");
strcat(defaultsettings, "<ignore>1</ignore>\n<enabled>1</enabled>\n");
strcat(defaultsettings, "<coordsEnabled>1</coordsEnabled>\n");
strcat(defaultsettings, "</location>\n<location>\n<string>Milky way</string>\n");
strcat(defaultsettings, "<x>\n<var>3500</var>\n<var>3850</var>\n</x>\n");
strcat(defaultsettings, "<y>\n<var>700</var>\n<var>950</var>\n</y>\n");
strcat(defaultsettings, "<ignore>1</ignore>\n<enabled>1</enabled>\n");
strcat(defaultsettings, "<coordsEnabled>1</coordsEnabled>\n");
strcat(defaultsettings, "</location>\n</locations>\n</CsSettings>");
printf("%s\nSize: %d\n\n",defaultsettings,sizeof(defaultsettings));

Output:

[...]
</location>
</locations>
</CsSettings>
Size: 23
  • 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-21T21:11:02+00:00Added an answer on May 21, 2026 at 9:11 pm

    Oh dear!

    Because you have only allocated memory for 23 chars on the first line, and are then overwriting unallocated memory for the rest of the data.

    You don’t actually need any of the strcat’s here, you can just use a feature of then C preprocessor that concatenates adjacent string literals:

    const char long_string[]  = "First line"
    "next line"
    "another line"
    "even more text";
    

    This will get you one array of the proper size.

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

Sidebar

Related Questions

Consider following code public class City { public string Name { get { return
Consider following code: My problem is: 1) I can't seem to cast the errors
Consider the following regular expressions: 7+ (7)+ Does anyone that is very familiar with
Consider the following example: // does not work foo( func_num_args() ); // works $args
Consider the following C function. Does opening the braces to create a local scope
Under what circumstances does the following example return a local x versus a global
Consider the following code which does not rollback the transaction if an exception is
Consider following two tables: tag_names (tag_id, tag_name) tag_links (tag_id, image_id) An image can have
Consider the following: - (id)initWithTitle:(NSString *)newTitle boxOfficeGross:(NSNumber *)newBoxOfficeGross summary:(NSString *)newSummary; What does this mean?
Consider the following definition: f[x_]=Piecewise[{{0,x<1/2},{Interval[{0,1}],x==1/2},{1,x>1/2}}]; Then when one does the Plot[f[x],{x,0,1}] of the function,

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.