Explain me what is happening

This is a discussion on Explain me what is happening within the C Programming forums, part of the General Programming Boards category; Please explain me what is happening Code: main() { int a[][3] = { 1,2,3 ,4,5,6}; int (*ptr)[3] =a; //Is address ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    21

    Unhappy Explain me what is happening

    Please explain me what is happening
    Code:
    main()
    {
      int a[][3] = { 1,2,3 ,4,5,6};
      int (*ptr)[3] =a;             //Is address of 'a' being assigned to (*ptr)[0] or (*ptr)[3]?
    
      printf("%d %d "  ,(*ptr)[1], (*ptr)[2] );
    
      ++ptr;
      printf("%d %d"  ,(*ptr)[1], (*ptr)[2] );
    }

  2. #2
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Its creating a pointer to the 2 dimensional array a, then printing out some of the content. Basically showing a different way to refer to arrays.


    EG: a[0][1] == (*ptr)[1] before the pointer gets incremented.

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,170
    int (*ptr)[3]
    Is just the pointer syntax to a 2D array with 3 columns, so you're just creating a pointer to the array.
    On a side note, main returns int and typically returns 0 at the end.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What is happening here please explain
    By jayee_spicyguy in forum C Programming
    Replies: 5
    Last Post: 09-23-2008, 05:27 AM
  2. Could someone explain this program?
    By Beachblue in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 06:51 AM
  3. Please explain?
    By neo_phyte in forum C Programming
    Replies: 3
    Last Post: 08-25-2006, 05:23 AM
  4. explain this loop statement?
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 05-05-2002, 02:46 AM
  5. Can someone explain "extern" to me?
    By valar_king in forum C++ Programming
    Replies: 3
    Last Post: 09-16-2001, 12:22 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21