C code clarification

Discussion in 'C Programming' started by satya123, Apr 7, 2011.

  1. satya123

    satya123

    Joined:
    Jul 6, 2010
    Messages:
    6
    Hi,

    To understand the C declaration and Pointers i have written the following sample code but not able to understand the output

    #include <stdio.h>

    int x[10] = { /* array of 10 integers */
    2,2,2,2,2,2,2,2,2
    };

    int (y)[10] = { /* array of 10 integers */
    1,2,3,4,5,6,7,8,9
    };

    main(){

    int (*px)[10], (*py)[10]; /* px and py declared as pointer to array 10 of integers

    px = &x; /* px is assigned x address*/
    py = &y; /* py is assigned y address */

    printf("x=%d, y=%d",*px,*py);
    }

    iam always getting the output x=404, y=464. is it possible for me to get the initial values of x and y i.e., 2 and 1?
    another clarification is if i declare a pointer such as px which is pointing to array 10 of integers can i initialize the px pointer to an array of different size?

    Thanks in advance.
    satya123, Apr 7, 2011
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nikos Mitas
    Replies:
    2
    Views:
    1,037
    Hubble
    Sep 27, 2005
  2. ss

    One Clarification

    ss, Aug 19, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    318
    Kevin Spencer
    Aug 19, 2003
  3. Ken Cox [Microsoft MVP]

    Database Connection clarification

    Ken Cox [Microsoft MVP], Nov 26, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    347
    Jon Booth
    Nov 26, 2003
  4. Alex Agranov

    Tabstrip clarification

    Alex Agranov, Jan 20, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    317
    Alex Agranov
    Jan 20, 2004
  5. Lerp

    Clarification Needed

    Lerp, Aug 17, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    340
    Edd Connolly
    Aug 18, 2004
Loading...

Share This Page