Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 21st, 2005, 9:30 AM   #1
81k5blzr
Newbie
 
Join Date: Mar 2005
Posts: 1
Rep Power: 0 81k5blzr is on a distinguished road
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.
81k5blzr is offline   Reply With Quote
Old Apr 21st, 2005, 12:53 PM   #2
java_roshan
Professional Programmer
 
Join Date: Mar 2005
Location: Student of University of Mumbai, Maharashtra State, India
Posts: 344
Rep Power: 4 java_roshan is on a distinguished road
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
java_roshan is offline   Reply With Quote
Old Apr 21st, 2005, 6:28 PM   #3
iignotus
Professional Programmer
 
iignotus's Avatar
 
Join Date: Apr 2005
Location: Nowhere Special
Posts: 466
Rep Power: 4 iignotus is on a distinguished road
Send a message via AIM to iignotus
>>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
iignotus is offline   Reply With Quote
Old Apr 30th, 2005, 7:14 PM   #4
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5 bl00dninja is on a distinguished road
and nothing more from that "member"
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:19 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC