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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:37:52+00:00 2026-05-27T10:37:52+00:00

Normally, if you do the following: int * i = &someint; It’s just a

  • 0

Normally, if you do the following:

int * i = &someint;

It’s just a pointer to a variable.

But, when you do

char * str = "somestring";

it automatically turns it into an array. Is it the pointer which is doing this, or is it just syntactic sugar for initialization syntax?

  • 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-27T10:37:53+00:00Added an answer on May 27, 2026 at 10:37 am

    No, the string literal "somestring" is already a character array, almost certainly created by your compiler.

    What that statement is doing is setting str to point to the first character. If you were to look at the underlying assembler code, it would probably look like:

    str314159:  db   "somestring", 0  ; all string literals here.
    : :         : :
                load r0, str314159    ; get address of string
                stor r0, -24[sp]      ; store it into local var str.
    

    In a large number of cases, an array will decay to a pointer to the first element of that array (with some limited exceptions such as when doing sizeof).


    By way of example, the following C code:

    #include <stdio.h>
    
    int main (void) {
        char *somestr = "Hello";
        puts (somestr);
        return 0;
    }
    

    when compiled with gcc -S to generate x86 assembly, gives us (with irrelevant cruft removed):

    .LC0:
        .string    "Hello"
        .text
    .globl main
        .type      main, @function
    main:
        pushl      %ebp                ; Standard set up of stack frame,
        movl       %esp, %ebp          ;   aligning and making
        andl       $-16, %esp          ;   room for
        subl       $32, %esp           ;   local variables.
    
        movl       $.LC0, 28(%esp)     ; Load address of string in to somestr.
    
        movl       28(%esp), %eax      ; Call puts with that variable.
        movl       %eax, (%esp)
        call       puts
    
        movl       $0, %eax            ; Set return code.
    
        leave                          ; Tear down stack frame and return.
        ret
    

    You can see that the address of the first character, .LC0, is indeed loaded into the somestr variable. And, while it may not be immediately obvious .string does create an array of characters terminated by the NUL character.

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

Sidebar

Related Questions

In the following code, I copy a string in to a char* str, which
I normally use the following code in SQL Server: IF EXISTS (SELECT * FROM
Normally if I run the following the following command in the rhino shell, mbp001:rhino1_7R2
Normally when I am writing the perl program . I used to include following
I don't normally go to stackoverflow for sigsegv errors, but I have done all
It seems at least weird to me... The program runs normally.But after I call
suppose I have the following serial C: int add(int* a, int* b, int n)
The following minimum code examples runs fine when it is terminated normally (by pressing
So assume I am mocking the following class: public class ClassAParams { public int
Normally, if I need to detect whether a type is const I just use

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.