C code clarification

Joined
Jul 6, 2010
Messages
6
Reaction score
0
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top