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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:16:52+00:00 2026-06-10T17:16:52+00:00

I am confused about the following line of code: char* words[] = { aaa,

  • 0

I am confused about the following line of code:

char* words[] = { "aaa", "bbbb", "ccccc", "dddddd" };

The way I understand, each word is first stored and then each position of the array words will point then to the first character of each word. How are these strings stored? Is there dynamic allocation going on here or are these words stored on the stack?

If they are stored on the stack, in which way are they stored? For instance, if I print some of the contents of words as below:

#include <stdio.h>
int main () {
    char* words[] = { "aaa", "bbbb", "ccccc", "dddddd" };
    printf("\n\n(*words)[0] = %s", words[0]);
    printf("\n\n(*words)[0]+1 = %s", words[0]+1);
    return 0;
}

instead of printing aaa and bbbb, what I get is aaa and aa. I do not really understand what is the reason for this since, the way I see it, words[0]+1 should point to the string bbbb and not to the second character of aaa. What is going on 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-10T17:16:54+00:00Added an answer on June 10, 2026 at 5:16 pm

    the way I see it, words[0]+1 should point to the string bbbb and not to the second character of aaa

    No. words[0] is a char pointer itself – it’s perfectly fine that you get the second character of “aaa” by adding one to it. What you want is words + 1 or &words[0] + 1 which will correctly be “bbbb”.

    Also, the strings themselves are allocated upon launching the executable and they’re probably put in the data or bss section of the binary by the linker. Also, when you declare and initialize words, it’ll be allocated on the stack as any other automatic array and its items will be assigned to pointers to the beginning of each string constant.

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

Sidebar

Related Questions

I have found following code on net. I am confused about the first line.
I am confused about getchar() 's role in the following code. I mean I
I'm confused about the errors generated by the following code . In Derived::doStuff, I
I'm confused about an aspect of polymorphism. Please consider the following code: #include <iostream>
I'm still confused about the behaviour of std::vector::resize() . Consider the following code (see
I'm new to OOP and I'm confused about this following line on chapter 6
I am little bit confused about following problem & their solutions: i have 2
Should be a simple question for SDL experts. I am confused about the following
I have the following line of code: sqlcommand.Parameters.Add(@LinkID, SqlDbType.Int, 4).Value = linkID; But, I'm
I'm working through NerdDinner and I'm a bit confused about the following section... First

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.