As others have said, you can easily do the first part. Just do pointer = array + 6. But what is pointer? It cannot be declared as:
char pointer[5];
or similar. It has to be a pointer:
char *pointer = array + 6;
This is because you can't assign an array to some other name (an array is not a modifiable l-value). It does not make sense to say:
char a[10];
char b[10];
b = a;
Now, in C, the size of a pointer is just the size of the pointer—since a pointer does not have a notion of "the number of units" of a given type pointed to. Arrays, on the other hand, know exactly how many elements they have, and you can get that size by an appropriate use of the sizeof operator.
So, sizeof array in your example would be 10 (if it has 10 elements), whereas sizeof pointer is going to be the number of bytes occupied by a char pointer. Therefore, what you ask in the second part of your question is impossible in C. In C++, you have access to data types that should allow you to do what you want.
Edit: To read a file in chunks:
Let's say you have a big buffer, that you're sure you can read the whole file into:
unsigned char bigbuf[1UL << 24]; /* or whatever you want */
unsigned char *ptr = bigbuf;
size_t chunk = BUFSIZ;
FILE *fp = fopen("foo.txt", "rb"); /* no error checking */
size_t nread;
size_t total = 0;
while ((nread = fread(ptr, 1, chunk, fp)) > 0) {
ptr += nread;
total += nread;
if (total + chunk > sizeof bigbuf) {
/* oops, not enough space */
}
}
if (ferror(fp)) {
/* read error */
} else {
/* bigbuf now has data, total has the number of bytes */
}
For unbuffered I/O, look at setvbuf(). But test buffered and unbuffered inputs to see which one is faster. Test different read sizes too.
Now an aside, which I had put in before, and I guess I will leave it in here anyway:
Having answered this question, more interesting is doing it the other way, i.e., given:
T a[10];
for any type T, can you declare pointer such that:
pointer[1] == a[0]
pointer[2] == a[1]
...
pointer[11] == a[10]
(or if you're feeling adventurous, replace 1 by a bigger positive number on the LHS of the first statement).
The answer, according to the C standard, is no. As mentioned in the link, Numerical Recipes in C made use of this 'trick'.
As an aside, I think you meant
pointer[0] == array[6];
and not
*pointer[0] == array[6];
in your question (similarly for *pointer[5])
sizeof(pointer) / sizeof(*pointer)(which is what I assume you meant by that last line) equal the array length. That's simply not how pointers work.freadcall. If you want no buffering, look atsetvbuf(), but test unbuffered first input to see if it's faster!