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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:32:03+00:00 2026-05-16T08:32:03+00:00

Using gcc 4.4.3 c89: I am just working on the following code below: I

  • 0

Using
gcc 4.4.3 c89:

I am just working on the following code below:

I just have some questions about dereferencing the src pointer. Which is declared in the calling function as:

char src[] = "device_id";

My confusion rests with dereferencing the src:

for(i = 0; src[i] != '\0'; i++) {
    printf("src %d: [ %s ]\n", i,  &src[i]);
}

src has decayed into a pointer. So src will be pointing to the first element in the array, which will be the character d:

src -> "device_id"

So when I do this src[i] I am dereferencing the value so it will return the character being currently pointing at. For this example when it gets to the nul it will break from the for loop.

For example i = 0

For &src[i] am I getting the address of the character instead of the character itself?
So where src[i] will dereference and return d, &src[i] will return the address of d.

Because *dest[] is an array of char pointers it is expecting an address. So here I am assigning an address of the character to the array of pointers to char.

dest[i] = &src[i];

Is there a difference to doing either this in the printf function for %s in using either &src[i] or src[i]:

printf("src %d: [ %s ]\n", i,  &src[i]);

or

printf("src %d: [ %s ]\n", i,  src[i]);

Source code:

void inc_array(char *src, size_t size)
{
    /* Array of pointers */
    char *dest[size];
    size_t i = 0;

    memset(dest, 0, size * (sizeof char*));

    /* Display contents of src */
    for(i = 0; src[i] != '\0'; i++) {
        printf("src %d: [ %s ]\n", i,  &src[i]);
    }

    /* copy contents to dest */
    for(i = 0; i < 9; i++) {
        dest[i] = &src[i];
    }

    /* Display the contest of dest */
    for(i = 0; *dest[i] != '\0'; i++) {
        printf("dest %d: [ %s ]\n", i, dest[i]);
    }
}

Many thanks for any suggestions,

  • 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-16T08:32:04+00:00Added an answer on May 16, 2026 at 8:32 am

    For &src[i] am I getting the address of the character instead of the character itself? So where src[i] will dereference and return d, &src[i] will return the address of d.

    src[i] is equivalent to *(src + i), so &src[i] is the same as &*(src + i), which can be reduced to src + i. It is just performing pointer arithmetic and no dereferencing takes place.

    src[i] gives you the character in src at index i, and &src[i] gives you a pointer to the ith character in src.

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

Sidebar

Related Questions

gcc 4.4.4 c89 I am using the code below. However, I keep getting the
gcc 4.4.2 c89 I have this code snippet that I have to repeat in
gcc 4.4.3 c89 I have the following source file. However, I get a stack
GCC compiles (using gcc --omit-frame-pointer -s ): int the_answer() { return 42; } into
I'm fine working on Linux using gcc as my C compiler but would like
I am using gcc 4.4.2 on linux I am just wondering does gcc automatically
gcc 4.4.4 c89 I was just experimenting with a int array. And something just
gcc 4.4.2 c89 I have a function that has to run (config_relays). It make
I am using gcc for windows . The OS is windows XP . How
I'm using GCC to generate a dependency file, but my build rules put the

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.