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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:37:54+00:00 2026-06-13T01:37:54+00:00

I know there is a lot c pointer tutotiral on the web and I

  • 0

I know there is a lot c pointer tutotiral on the web and I did read them. However I still confuse about some part of the pointer. For example, I have an array unsigned char M[10000], now I want to store the values in the array using pointer way instead of specifying the index , my code below has an error.

//starting to put value into M[0]
*(char*)&M='1';
//increase the address to M[1]
&M++;
//input value at M[1]
*(char*)&M='a';

from my understanding, when I do &M++ I am increasing the address to 1 byte, where is the place of M[1] stands, but there is an error. I am new to c, thanks for help.

detailed code- updated:

#include <stdio.h>
#include <stdlib.h>

int eax,ebx,ecx,edx,esi,edi,ebp,esp;
unsigned char M[10000];

void exec(void){
    *M= 'a';
    M++ ;
    //append space behind a
    *(char*)&M += ' ' ;
    *(char*)&M += 'b' ;
}

int main() {
    exec();
    print(M);
}

I am using gcc and codeblock

  • 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-13T01:37:55+00:00Added an answer on June 13, 2026 at 1:37 am

    An array variable name can be considered to be a constant pointer. While it can be treated as a pointer, the variable name value can not be modified.

    For instance we can create an array and then access an element of the array by either using subscripts or by using pointer arithmetic and dereferencing using the asterisk (*) symbol.

    char myArray[20];    // an array of 20 characters
    
    myArray[2] = 'C';    // assigning a value of the letter C to the third element of the array
    *(myArray + 2) = 'K';  // assigning a value of the letter K to third element of the array
    
    
    char *pmyArray;      // a pointer to one or more characters, not yet initialized though.
    pmyArray = myArray;  // assigning the address of the first element of the array to my pointer
    *(pmyArray + 2) = 'J';     // assigning a value of the letter J to third character after the character pointed to by pmyArray
    

    The value of a pointer can be incremented. For example:

    pmyArray++;    // increment by one position
    pmyArray = pmyArray + 1;    // increment by one position
    pmyArray += 1;       // increment by one position
    

    However the array name is not a true pointer variable it is more like a pointer constant so an array name can not be incremented in the way that a pointer variable can be incremented. The nice thing about a pointer that is incremented is that the actual address is increased by the number of bytes needed to move the pointer to the address of the next memory address for the type.

    For example:

    char myArray[48];
    char *pmyChar = myArray;
    short *pmyShort = (short *)myArray;  // use cast to assign address of array to pointer
    long  *pmyLong = (long *)myArray;
    

    With these statements, the three different pointers will all point to the same memory address, the address where the character array myArray begins. However if we then increment each of these pointers like so:

    pmyChar++;      // increment by one to next character
    pmyShort++;     // increment by one to next short
    pmyLong++;      // increment by one to next long
    

    each of these pointers will now contain a different address. The pointer pmyChar will contain the address of the second element of the character array myArray because pmyChar is a char pointer just as the myArray is a char array.

    The pointer pmyShort will contain the address of the third element of the character array myArray because pmyShort is a short pointer, a short contains two bytes (each char is a byte), and the incrementing of pmyShort is done by increasing the address contained in the pointer variable by the size of a short and not by the size of a char.

    The pointer pmyLong will contain the address of the fifth element of the character array myArray because pmyLong is a long pointer, a long contains four bytes, and the incrementing of pmyLong is done by increasing the address contained in the pointer variable by the size of a long and not by the size of a char.

    You can also have a pointer to a pointer like the following:

    char myArray[48];
    char *pmyArray;
    char **pmyPointerToMyArray;
    
    pmyArray = myArray;                 // pointer to myArray
    pmyPointerToMyArray = &pmyArray;    // address of pointer to myArray
    

    Then you can do something like this:

    pmyArray++;   // increment to second element of myArray
    *(pmyArray) = 'J';  // set the second element of myArray to letter J
    *(*pmyPointerToMyArray) = 'K';  // set the second element of myArray to letter K
    

    What this last statement does is to get the value pointed to by pmyPointerToMyArray, which is the address of the variable pmyArray, and to then use that value as the address of a character to put the letter K.

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

Sidebar

Related Questions

I know there is a lot of thread about this problem but I dont
I wanted to ask for some help. I know, that there are a lot
I know there a lot of similar questions to this, but I didn't find
I know there is a lot on this topic but I can't get any
I know there are a lot of similar questions on SF, but I think
I know there are a lot of questions around on this subject, but I've
I know there are a lot of posts related to this particular error but
I know there are a lot of such questions on stackoverflow but I couldn't
I know there are a lot of questions similar to mine, but I actually
I know there are a lot of questions regarding date and time for Rails,

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.