# Math with Array's

Page 1 of 1

## 2 Replies - 191 Views - Last Post: 03 March 2018 - 05:52 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=409628&amp;s=bb53abcb00b9238f341e123591888320&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Noel12345678

Reputation: 0
• Posts: 13
• Joined: 14-February 18

# Math with Array's

Posted 02 March 2018 - 11:23 AM

Here's a test question. I do NOT understand why the LETTERS in the array change the answer. Please explain.

If the array is "ABCDE" the answer is -2 (try it...)
...but if "CABDE" the answer becomes 1 (and my IDE reproduces this)

```#include<stdio.h>
#include<string.h>

int main(void)
{
char s[11]="ABCDE";

printf("the value of s = %d, and s+2 = %d, and s[0] = and s[2]= \n\n", s, s+2, s[0], s[2]);

strcat(s+2, "ABCDE");
printf("%s", char s);
printf("%d", s[0]-s[2]);
return 0;
}

#include<stdio.h>
#include<string.h>

int main(void)
{
char s[11]="CABDE";

printf("the value of s = %d, and s+2 = %d, and s[0] = and s[2]= \n\n", s, s+2, s[0], s[2]);

strcat(s+2, "CABDE");
printf("%s", char s);
printf("%d", s[0]-s[2]);
return 0;
}
```

This post has been edited by ndc85430: 02 March 2018 - 11:25 AM
Reason for edit:: Added code tags. Please do this yourself in future.

Is This A Good Question/Topic? 0

## Replies To: Math with Array's

### #2 modi123_1

• Suitor #2

Reputation: 13868
• Posts: 55,372
• Joined: 12-June 08

## Re: Math with Array's

Posted 02 March 2018 - 11:43 AM

Have you considered that letters are value represented, in ascii, as numbers.

https://www.asciitable.com/

So A corresponds to 65.. and C to 67.

### #3 Noel12345678

Reputation: 0
• Posts: 13
• Joined: 14-February 18

## Re: Math with Array's

Posted 03 March 2018 - 05:52 AM

THAT WAS IT!

Thank you