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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:01:28+00:00 2026-05-16T17:01:28+00:00

I am really getting confused on how pointers work. I am trying to write

  • 0

I am really getting confused on how pointers work. I am trying to write short little programs that will illuminate exactly how they work and I am having some troubles. For example:

char c[3]; //Creates an array of 3 bytes - the first 2 bytes can be used for characters and the 3rd would need to be used for the terminating zero

*c = 'a'; //sets c[0] to 'a'
*c++; //moves the pointer to c[1]
*c = 'b'; //sets c[1] to 'b'
*c++; //moves the pointer to c[2]
*c = '\0' //sets c[2] to the terminating zero

Obviously this code is not correct, or else I wouldn’t be polling the forum 🙂

I am just having some troubles understanding this from a book, can anyone briefly explain the concept?

  • 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-16T17:01:29+00:00Added an answer on May 16, 2026 at 5:01 pm

    First of all, c here is not a pointer, it’s an array. Arrays can in some contexts be used like pointers, but they are not the same thing. In particular, you can use *c (as if it were a pointer) to access the value in the first position, but since c is not really a pointer, you can’t change where c points by using c++.

    Second, you are misunderstanding what * means. It’s not just a decoration you use when using pointers. As an operator, it means “dereference”, i.e. give me access to what is being pointed to. Therefore when you are manipulating the pointer itself (by, for example, incrementing it) and not manipulating the pointed-to data, you need not use it.

    Here is what you probably wanted:

    char c[3]; // Creates an array of 3 bytes - the first 2 bytes can be used for characters 
               // and the 3rd would need to be used for the terminating zero
    char* p_c; // Creates a character pointer that we will use to refer into the c array
    
    p_c = &c[0]; // Assign the address of the first element of the c array to the p_c pointer.
                 // This could also be "p_c = c", taking advantage of the fact that in this
                 // is one of the circumstances in which an array can be treated as if it were 
                 // a pointer to its first element
    
    *p_c = 'a'; //sets c[0] to 'a'
    p_c++;      //moves the pointer to c[1] (note no *)
    *p_c = 'b'; //sets c[1] to 'b'
    p_c++;      //moves the pointer to c[2] (note no *)
    *p_c = '\0' //sets c[2] to the terminating zero
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am really confused by the different properties that exist in JavaScript for getting
I'm really getting confused by how many different ways there is to write data
I'm trying to write up a user management app, but getting confused about how
I am getting really confused with this concept: If I want to implement a
This is really getting to me now.I have a form that loads when the
I am having a really hard time getting this to work. I have two
I'm having a really tough time getting XMPPFramework to work. I've followed every direction
Ok I am really confused. Right now I am working on getting a datagrid
I'm getting really confused over how to connect to MongoLab on Heroku. To connect
I think I'm getting really confused with return'ing and echo'ing variables. I've got this

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.