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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:50:07+00:00 2026-06-03T15:50:07+00:00

In this example seems that both strings jesus are equals(same memory location). printf(%p\n,jesus); printf(%p\n,jesus);

  • 0

In this example seems that both strings “jesus” are equals(same memory location).

printf("%p\n","jesus");
printf("%p\n","jesus");

Also note that:

printf("%p\n",&"jesus");
printf("%p\n","jesus");

prints the same, but:

char* ptrToString = "jesus";
char* ptrToString = &"jesus"; //ERROR

So i wanna know how an unassigned string is stored in memory and how to point it…

  • 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-03T15:50:08+00:00Added an answer on June 3, 2026 at 3:50 pm

    First off, why are "jesus" and &"jesus" the same: "jesus" is an array of type const char[6], and it decays to a pointer to the first element. Taking the address of the array gives you a pointer to an array, whose type is const char (*)[6]. However, the pointer to the array is numerically the same as the pointer to its first element (only the types differ).

    This also explains why you have an error in the last line – type type is wrong. You need:

     const char (*pj)[6] = &"jesus";
    

    Finally, the question is whether repeated string literals have the same address or not. This is entirely up to the compiler. If it were very naive, it could store a separate copy for each occurrence of a string literal in the source code. If it is slightly cleverer, it’ll only store one unique copy for each string literal. String literals are of course stored in memory somewhere, typically in a read-only data segment of the program image. Think of them as statically initialized global variables.

    One more thing: Your original code is actually undefined behaviour, since %p expects a void * argument, and not a const char * or a const char (*)[6]. So the correct code is:

    printf("%p\n%p\n", (void const *)"jesus", (void const *)&"jesus");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was reading thourg this example (link) ... From the description, this seems paradox
I have this simple example I can't seems to get working : MERGE INTO
For example this article introduces them. What is the benefit? Static analysis seems cool
This is an example from a book, a bit modified. It seems like sessions
I am learning ADO.NET entity framework. This is my first example. The datagrid seems
This example works great for one or the other, but not both: public void
I've scourged the internet for an example that would use both spring-json and annotated
It seems that when using a primitive type (string, number) as the this subject
If I have a Server/Client application that both reference the same DLL which contains
This example uses a StringWriter to hold the serialized data, then calling ToString() gives

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.