# Thread: Few questions: Bytes, Arrays, Declarations, and Buff

1. ## Few questions: Bytes, Arrays, Declarations, and Buff

I had a few questions from my study guide...for my upcoming final

The first one is on arrays:

Code:
```How many bytes are in the following array?
char list [20] = "Exercise 1";```
My answer for this is 20 because i was under the impression that each part of the list is a byte...however, i really doubt that this is true.

How does "Exercise1" play a role in this?

Next problem... Given the following declarations:

Code:
```float list [20], *plist, value = 2.2;
int i = 3;```
Code:
```Identify each of the following statements as valid or invalid:
a.  list[2] = value;
b.  scanf ("%f", &list[I]);
c.  list = value;
d.  value = list;
e.  plist = value;
f.  plist = list;```
a. valid
b. valid
c. invalid
d. invalid
e. valid
f. valid

Last Question:

Code:
```given the following declaration:
int buff[30];

express the address of buff[0] in two different ways```
I tried looking up the buff command but i can't find a clear definition...I don't know what this means

2. Originally Posted by viciousv322
Code:
```How many bytes are in the following array?
char list [20] = "Exercise 1";```
My answer for this is 20 because i was under the impression that each part of the list is a byte...however, i really doubt that this is true.
There are 20 bytes in the array.
Originally Posted by viciousv322
How does "Exercise1" play a role in this?
It does nothing for the size, but it initializes the data in the array.

Originally Posted by viciousv322
Next problem... Given the following declarations:
Code:
```float list [20], *plist, value = 2.2;
int i = 3;```
Code:
```Identify each of the following statements as valid or invalid:
a.  list[2] = value;
b.  scanf ("%f", &list[I]);
c.  list = value;
d.  value = list;
e.  plist = value;
f.  plist = list;```
a. valid
b. valid (if I was supposed to be lowercase)
c. invalid
d. invalid
e. valid (did you think it was *plist = value?)
f. valid
Originally Posted by viciousv322
Code:
```given the following declaration:
int buff[30];

express the address of buff[0] in two different ways```
I tried looking up the buff command but i can't find a clear definition...I don't know what this means
There is buff, which is the same as &buff[0].

3. I didn't even notice the I was not lowercase...thanks for the colored comments. Are my other answers correct?

What do you mean by... "There is buff"? Is that what the question means by expressing the address of buff? ( as in &buff[0] )

4. Code:
`int buff[30];`
The above declares an int array of 30 elements called buff. There is obviously no "buff command", it's just the name of the identifier.

When you want the address of an arbitrary element of an array, you can use the & operator, as with any other addressable data.

Example, for the address of buff[5], you'd use &buff[5].

However, since buff[i] is shorthand for *(buff + i), then buff[0] is shorthand for *(buff + 0) and since + 0 does nothing, it's short for *(buff).

So, to get the address of *(buff) you apply &, which cancels out the *, and you are left with buff.

In general, the address of buff[i] is buff + i and &buff[i].

Hope that is clearer than mud.

5. so would it be correct to say the address of buff[0] is buff+0 and &buff[0]

Also, for the declarations are these answers correct?

a. valid
b. invalid
c. invalid
d. invalid
e. invalid
f. valid

6. Dave already answered about the declarations. See his signature above.. It's a bit early in the USA for him to have had enough cheap american beer to start making any mistakes

7. Should we tell them about:
Code:
`&0[buf]`
Or would it be too much too fast?
Code:
```#include<stdio.h>
int main( void )
{
char buf[] = "Hello World!\n";
size_t x;

for( x = 0; x[buf]; x++ )
{
putchar( *&x[buf] );
}

/* edit - common fun variant */
for( x = 0; x["Hello World!\n"]; x++ )
{
putchar( x["Hello World!\n"] );
}

return 0;
}```
Quzah.

8. Well I think I already implied that due to the commutative properties of the + operator.