# Problem in Array and Pointer

Page 1 of 1

## 2 Replies - 370 Views - Last Post: 10 November 2012 - 06:21 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=299537&amp;s=c3b888f769144f0fad37e83f8eda7dbf&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 NeeZaaR

• New D.I.C Head

Reputation: -2
• Posts: 39
• Joined: 29-August 12

# Problem in Array and Pointer

Posted 10 November 2012 - 05:31 AM

How i can make the sum = &ptr?
to make the pointer and address for student[i]

```#include<stdio.h>
void main()
{
int *ptr;
int i,sum,num=1;
int students[]={6,4,8,3};
for (i=0; i<4;i++)
{
printf("%d - The Value For Student is %d\n",num++,students[i]);
sum=students[i];
*ptr=sum;
printf("%d - the value for Student[%d] is %d, has Pointer is %d and  has Address is %d \n",num++,i,students[i],*ptr,&ptr);
}
}

```

Is This A Good Question/Topic? 0

## Replies To: Problem in Array and Pointer

### #2 Xupicor

• Nasal Demon

Reputation: 373
• Posts: 957
• Joined: 31-May 11

## Re: Problem in Array and Pointer

Posted 10 November 2012 - 06:04 AM

First, that's int main! And do return 0 from main, to signify everything went ok.

See printf docs, there's a special format specifier for addresses, it's %p.

I'm not sure what you want. Can you state your problem in a more specific manner?

Also - you don't really sum your values... And if you would - you'd get strange values due to uninitialized variable.

### #3 jimblumberg

Reputation: 4736
• Posts: 14,769
• Joined: 25-December 09

## Re: Problem in Array and Pointer

Posted 10 November 2012 - 06:21 AM

You may also want to study the following links on Pointers, and Pointer abstraction and Arrays.

Here is a slight reworking of your program to show some of the different values:
```#include<stdio.h>
int main()
{
int *ptr;

int i,sum,num=1;
int students[]= {6,4,8,3};
for (i=0; i<4; i++)
{
sum=students[i];
ptr=&sum;
printf("%d - The value contained in",num++);
printf(" students[%d] is %d", i, students[i]);
printf(" and the address is %p,", (void*)&students[i]);
printf(" sum contains the value %d", sum);
printf(" and the address of sum is %p,", (void*)&sum);
printf(" the address of ptr is %p", (void*)ptr);
printf(" and the value pointed to is %d\n", *ptr);
}
}

```

Jim

This post has been edited by jimblumberg: 10 November 2012 - 06:21 AM