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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:44:38+00:00 2026-06-01T07:44:38+00:00

Are C strings (as opposed to std::string ) guaranteed to be implemented as arrays?

  • 0

Are C strings (as opposed to std::string) guaranteed to be implemented as arrays? For example, say, I have

char const * str = "abc";

What it boils down to is whether or not str + 4 a legal pointer value (without dereferencing that is). I’m asking this because I dont know if C strings are a special case due to the null character terminating 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-01T07:44:39+00:00Added an answer on June 1, 2026 at 7:44 am

    First part of the question

    Are C strings guaranteed to be implemented as arrays?

    For example, say, I have: char const * str = "abc"

    Yes, a string object is of an array type. A character string is a data format and a (character) string object is of a type array of char.

    In your example str points to the string literal "abc". Character string literals have the type char[N+1] where N is the length of the string (i.e., the number of characters excluding the terminating null character).

    Some references from Standard and K&R 2nd edition:

    C defines a string literal as:

    (C99, 6.4.5p2) “A character string literal is a sequence of zero or more multibyte characters enclosed in double-quotes, as in “xyz”.”

    and says (emphasis mine):

    C99, 6.4.5p5) “For character string literals, the array elements have type char, and are initialized with the individual bytes of the multibyte character sequence;”

    K&R 2nd edition says:

    “Technically, a string constant is an array of characters”

    and

    “when a string constant like "hello\n" appears in a C program, it is stored as an array of characters containing the characters in the string and terminated with a '\0' to mark the end.”

    Second part of the question

    What it boils down to is whether or not str + 4 a legal pointer value (without dereferencing that is).

    Yes, it is a valid pointer. In your case str + 4 is a pointer one past the last element of the array.

    A valid pointer is a pointer that is either a null pointer or a pointer to a valid object. For an element of an array object, a pointer one past the last element of the array object is also a valid pointer.

    Note that for the purpose of the last rule (“the one past element”), for pointers to objects that are not elements of an array, C treats the object as an array of one element.

    (C99, 6.5.6p7) “For the purposes of these operators, a pointer to an object that is not an element of an array behaves the same as a pointer to the first element of an array of length one with the type of the object as its element type.”

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

Sidebar

Related Questions

Are strings compared lexicographical when using the overriden bool operator<(const std::string & rhs) operator?
Say I have two strings, String s1 = AbBaCca; String s2 = bac; I
Delphi strings use single quotes, for example ' a valid string '. How does
If you have binary strings (literally String objects that contain only 1's and 0's),
Strings are immutable, meaning, once they have been created they cannot be changed. So,
I have 2 strings that I'd like to compare, and return the positions of
I have some strings of xxh:yym format where xx is hours and yy is
Consider: delete new std :: string [2]; delete [] new std :: string; Everyone
I have an array of strings that I would like to use the join
I have a std::vector and I want to check all the elements in it.

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.