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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:02:04+00:00 2026-05-23T10:02:04+00:00

I am trying to understand how the pointers are moving. Following is the program

  • 0

I am trying to understand how the pointers are moving.
Following is the program and I am aware that
if

int cs={1,2,3};  

then cs points to cs[0]
what I am not clear is what is *cs pointing to.

#include<stdio.h>
int main()
{
        int array[] = { 1, 2, 3, 4, 5 };
        int *arrptr1 = array;
        int *arrptr = array;
        int i;
        for (i = 0; i < sizeof(array) / sizeof(int); i++) {
                printf("%d, %d, %d\n", array[i], *arrptr1++, *arrptr + i);
        }
}

the output of above program is

1, 1, 1
2, 2, 2
3, 3, 3
4, 4, 4
5, 5, 5

then my understanding *arrptr should increase the value stored at

*arrptr

should get incremented by 1.
Where as what I observe is the pointer is moving to next location.So just want to know what is wrong in my understanding?

UPDATE
As per the replies below I understand that

print("%d", *arrptr1++);

in such a statement evaluation of operators is from right to left.
Hence in *arrptr1++ the ++ will get evaluated first and then arrptr and then *
So to confirm the same I wrote another program

#include<stdio.h>
int main()
{
        int array[] = { 10, 20, 30, 40, 50 };
        int *q1 = array;
        printf("q1 = %p\n",q1);
      printf("*q1++ = %d\n",*q1++);
        printf("q1 = %p\n",q1);
      printf("*q1++ = %d\n",*q1);
}

The output of above program is different than the expected operator precedence by above logic.
The output I got is

q1 = 0x7ffffcff02e0
*q1++ = 10
q1 = 0x7ffffcff02e4
*q1++ = 20

So I was expecting in the 2nd line of output instead of *q1++ = 10 following *q1++ = 20
so did the operator precedence not happened right to left?

  • 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-23T10:02:05+00:00Added an answer on May 23, 2026 at 10:02 am

    What happens is that *arrptr1++ is interpreted as *(arrptr1++), which means that the pointer to the array is increased by one each time in the loop, and hence it will point to the same element as array[i]. *arrptr + i on the other hand is interpreted as “the value of the array element pointed to by arrptr plus the integer i“. In this loop it means it will display the same thing as array[i], but it is not pointing at the same element (arrptr is always pointing to the first element in your array). If you change the values in the array to something more random, it should be obvious when you run the program again.

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

Sidebar

Related Questions

I was trying to understand something with pointers, so I wrote this code: #include
I thought that I was really starting to understand how pointers work, and then
I have been trying to understand function pointers in C++ so that I can
After trying to understand why client code is not rendered in a page (injected
I've been trying to understand how Ruby blocks work, and to do that I've
I'm trying to understand how pointers to statically allocated objects work and where they
I'm a programming student trying to better understand pointers, one of the things I
In my program I am trying to resize array using malloc function. #include <stdio.h>
I am trying to understand the practical difference during the execution of a program
This is probably simple, but im trying to try and understand pointers better. Lets

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.