d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Quick Array Question > Topic
Add Reply New Topic New Poll
Member
Posts: 2,881
Joined: Nov 3 2009
Gold: 1,378.00
Dec 9 2012 02:27pm
what does arr[7] +=200; and arr[4] --; mean and what does it change it to?o.O

#include <iostream>
int main()
{
int arr[10];

for (int j = 2; j <= 8; j++)
arr[j] = 10* j;
for (int k = 0; k <=9 ;k++)
cout << arr[k] << " ";
cout << endl << endl;

arr[7] +=200;
arr[4] --;
arr[0] = 7;

return 0;
}
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Dec 9 2012 02:32pm
seems like it would take the values, respectively in each element, and modify them

the first case taking the value and adding 200 to it, the second case taking the value and decreasing it by one.
Member
Posts: 2,881
Joined: Nov 3 2009
Gold: 1,378.00
Dec 9 2012 02:36pm
Quote (Eep @ Dec 9 2012 03:32pm)
seems like it would take the values, respectively in each element, and modify them

the first case taking the value and adding 200 to it, the second case taking the value and decreasing it by one.


but what if is were to say that:

two = "baseball";
two[3]++;
two[4]='Q';
two[5]='9';
cout<<two<<endl;

what would it change it to?o.O
Member
Posts: 2,425
Joined: Aug 17 2007
Gold: 3,754.50
Dec 9 2012 02:43pm
"basfQ9ll"

two[3]++;
adds one to the 'e'

two[4]='Q';
changes 'b' to 'Q'

two[5]='9';
changes 'a' to '9'
Member
Posts: 2,881
Joined: Nov 3 2009
Gold: 1,378.00
Dec 9 2012 02:46pm
Quote (InsainoMan @ Dec 9 2012 03:43pm)
"basfQ9ll"

two[3]++;
adds one to the 'e'

two[4]='Q';
changes 'b' to 'Q'

two[5]='9';
changes 'a' to '9'



so u can ++ or -- still works for alphabets too, i see. ty!
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Dec 9 2012 03:14pm
Quote (emopker2 @ Dec 9 2012 03:46pm)
so u can ++ or -- still works for alphabets too, i see. ty!


how do you think alphabetical characters are represented in computers? They work similar to ASCII values iirc. So every letter, symbol etc has some sort of integer value associated with it. Thus adding '1' to 'e' does make sense.

This post was edited by Eep on Dec 9 2012 03:14pm
Member
Posts: 4,605
Joined: Sep 15 2011
Gold: 9,464.00
Dec 9 2012 10:25pm
Quote (Eep @ Dec 9 2012 02:14pm)
how do you think alphabetical characters are represented in computers? They work similar to ASCII values iirc. So every letter, symbol etc has some sort of integer value associated with it. Thus adding '1' to 'e' does make sense.


strictly speaking, it depends on the character encoding as well as the language.
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Dec 9 2012 10:52pm
Quote (irimi @ Dec 9 2012 11:25pm)
strictly speaking, it depends on the character encoding as well as the language.


yeah I forgot about the fact there are multiple encodings
Member
Posts: 7,002
Joined: Feb 15 2010
Gold: Locked
Trader: Scammer
Warn: 30%
Dec 10 2012 09:17am
Quote (Eep @ Dec 9 2012 02:32pm)
seems like it would take the values, respectively in each element, and modify them

the first case taking the value and adding 200 to it, the second case taking the value and decreasing it by one.


decrementation in c++ is x-- not x-
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Dec 10 2012 12:30pm
Quote (Tokiko @ Dec 10 2012 10:17am)
decrementation in c++ is  x-- not x-


Quote
what does arr[7] +=200; and arr[4] --; mean and what does it change it to?o.O


and?

This post was edited by Eep on Dec 10 2012 12:30pm
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll