![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2005
Posts: 1
Rep Power: 0
![]() |
array help
Here are a couple of questions I have about arrays?
First of all can I subscript an array using (char, float, or short)? My next question is about two dimensional arrays. I have the following initialization: int a[][4] = {{1,2,3,4z},{5,6,7,8}}; Could somebody explain how I get the value for the expression: *(a[1]+2). I know these are basic questions but I am having a problem grasping c. So any help is greatly appreciated. |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Mar 2005
Location: Student of University of Mumbai, Maharashtra State, India
Posts: 344
Rep Power: 4
![]() |
An array cannot have float or char as its subscript. I am not sure about short. However, I will try to find out and answer.
For the second question I need to go through the material (I dont remember things ......I forget a lot) ....
__________________
Visit: http://www.somaiya.edu |
|
|
|
|
|
#3 |
|
Professional Programmer
|
>>First of all can I subscript an array using (char, float, or short)?
Any positive integer (long int, short int, unsigned int, int, etc) should work to subscript the array. >>int a[][4] = {{1,2,3,4z},{5,6,7,8}}; Should be, as far as I know, int a[2][4] = {{1,2,3,4},{5,6,7,8}}; No z. >>Could somebody explain how I get the value for the expression: *(a[1]+2). I'm taking that * as a multiplication, and that by a[1] you want the number 2 (remember, arrays script from [0], not [1]; [0] is the first element). Also, you need to specify a subscript for the first array as well as the last in a 2-d array. Example: int x = 10; int y = a[0][1]; // should be the number 2 int z = x+(y+2); // should be what you're looking for: 14 Also: int x = 10; int z = (x+((a[0][1])+2); // z should equal 14 here, too Now, I'm not 100% sure but this seems the way to go. Unforunately, even my array work is rusty. Hope this helps.
__________________
% rc4 hexkey < input > output
#define S ,t=s[i],s[i]=s[j],s[j]=t /* rc4 hexkey <file */
unsigned char k[256],s[256],i,j,t;main(c,v,e)char**v;{++v;while(++i)s[
i]=i;for(c=0;*(*v)++;k[c++]=e)sscanf((*v)++-1,"%2x",&e);while(j+=s[i]
+k[i%c]S,++i);for(j=0;c=~getchar();putchar(~c^s[t+=s[i]]))j+=s[++i]S;}Last edited by iignotus; Apr 21st, 2005 at 6:29 PM. Reason: clarity |
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5
![]() |
and nothing more from that "member"
__________________
i put on my robe and wizard hat... Have you ever heard of Plato, Aristotle, Socrates?...Morons. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|