int abc[]={1,2,3,4,5,6,7,8,9,10}; array behv

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Humaira
    New Member
    • Aug 2012
    • 4

    int abc[]={1,2,3,4,5,6,7,8,9,10}; array behv

    i want to knw abt the behavior of this array int abc[]={1,2,3,4,5,6,7 ,8,9,10}; ?


    int abc[]={1,2,3,4,5,6,7 ,8,9,10};

    for (int i=0; i< 10 ; ++i){

    cout<<*abc;
    abc++; // why is this thing not working ??


    }
    cout<<*abc<<end l;
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    You will have to understand the behave of pointer.
    when you define like this
    Code:
    int abc[]={1,2,3,4,5,6,7,8,9,10};
    compiler creates an array name abc with length of 10 and set the value you put.

    now its an array and also abc is a pointer. abc is pointing on some address.

    so, if you print abc you will actually print the address of abc;

    I will have to go, you better read about accessing pointer

    Comment

    • nextstep
      New Member
      • Aug 2012
      • 14

      #3
      you delare:
      int abc[]={1,2,3,4,5,6,7 ,8,9,10};

      after that, abc variable will become constant pointer point to the first element in this array and it means you can not change the value of it.

      so operation:
      abc++;

      is impossible.

      Comment

      • johny10151981
        Top Contributor
        • Jan 2010
        • 1059

        #4
        good catch. very important point. what compiler are you using?

        Comment

        • Humaira
          New Member
          • Aug 2012
          • 4

          #5
          i am using visual studio 2010.. sometimes codeblock .

          Comment

          • Humaira
            New Member
            • Aug 2012
            • 4

            #6
            @nextstep u explained this problem very beautifully .. thank u so much everyone ...

            Comment

            Working...