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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:40:25+00:00 2026-06-13T10:40:25+00:00

I am having a conceptual doubt. char ch[20]=some string; I wanted to know how

  • 0

I am having a conceptual doubt.

char ch[20]="some string";

I wanted to know how ch is being stored i.e. whether 20 bytes are allocated or just the length of the string assigned to it? Can we access something like ch[18] here?

  • 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-13T10:40:26+00:00Added an answer on June 13, 2026 at 10:40 am

    I wanted to know how ch is being stored i.e. whether 20 bytes are allocated or just the length of the string assigned to it?

    It creates an array by name ch which is 20 characters long and initalizes it with “some string”.
    Yes, the array is 20 bytes in size.

    Can we access something like ch[18] here?

    Yes We can. And even modify the contents.

    Good Read:

    What is the difference between char a[] = “string”; and char *p = “string”;


    To answer Q in comment:

         +---+---+---+---+---+---+----+----+----+----+----+----+----+      +----+----+
      ch:| s | o | m | e |   | s |  t |  r |  i |  n |  g | \0 |    |      | b  | \0 |
         +---+---+---+---+---+---+----+----+----+----+----+----+----+      +----+----+
           0   1   2   3   4   5   6    7    8     9   10   11   12  ......  18   19
    

    When you do,

     ch[18]='b';   
    

    The modification has happend only that you cannot see it.
    printf determines the end of string by detecting \0. The \0 was placed at the end of the string when you initialized it.The rule in C/C++ while declaring an array whenever initializers are given, any uninitialized elements are automatically set to 0. As you see in above the diagram depiction the modified character is placed after what printf thinks is end of string and hence you cannot see it in output of printf.

    If you output the string each character by a for-loop by iterating over it, You can see your modification.

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

Sidebar

Related Questions

Ok, so this is really just a conceptual question I'm having a bit of
I'm having some conceptual trouble on figuring out how to best implement this... I
Okay. I'm having some conceptual issues with a WCF service i want to create.
Having read Apple's numerous documentation on icon guidelines: http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/MobileHIG/IconsImages/IconsImages.html#//apple_ref/doc/uid/TP40006556-CH14-SW2 http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/App-RelatedResources/App-RelatedResources.html#//apple_ref/doc/uid/TP40007072-CH6-SW1 http://developer.apple.com/library/ios/#qa/qa1686/_index.html I was wondering
Having just added a new button in my web application, I get an error
I'm having a conceptual problem here, I have like this: abstract class A {
I'm just starting to work with Silverlight (no WPF experience either) and am having
I am new to iOS/objective-C and I wanted to know how to build custom
I'm having a conceptual problem. I have this asp.net page to manage code snippets.
I'm having trouble understanding some concepts. In the Unicode spec, there's a property called

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.