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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:49:31+00:00 2026-06-04T10:49:31+00:00

char str[]=Hello; this allocates 6 bytes for the string , but if i write

  • 0
char str[]="Hello";

this allocates 6 bytes for the string , but if i write

char *str = "Hello";

will this overwrite data because it was just meant to store 1 char? So what i’m asking is that when i declare a string, but not initialize it (char str[12]; ) , do 12 bytes get reserved here or when i initialize it? And if they do get initialized here, so that means that in:

char *str;

only 1 byte gets reserved, but when i make it point to a string, doesn’t that overwrite data beyond it’s bounds?

  • 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-04T10:49:33+00:00Added an answer on June 4, 2026 at 10:49 am
    char *str;
    

    does not reserve any data for content. It is a pointer, sized to hold a memory address.

    char *str = "Hello";
    

    6 bytes for { 'H', 'e', 'l', 'l', 'o', 0 } already has been stored somewhere by the compiler. Now you are making a variable holding its address (pointing to it). The string content is not copied.

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

Sidebar

Related Questions

I have a string as const char *str = Hello, this is an example
Will this leak memory? char *str = Hello/World; char *pos = rindex(str, '/'); *pos
I have the following string: const char *str = \This is just some random
Can anyone explain this to me , String str = Hello; str += ((char)97)
I have this in an exercise with pointers: char *str = Hello; int count
Now i have this code, but it always set null UNICODE_STRING str; char *cmp
An example of this would be: char str[] = Hello; int strLength = strlen(str);
Sample input string: char *str = 12345.567675; And the desired output if I need
Suppose I have a string char* str . I print it to the buffer
Is something like this possible in C? #include <stdio.h> void print_str(char *str) { printf(str);

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.