How to decipher this C declaration?
If you look at the declaration below for Gnu C:
Quote:
Code:
#include <stdio.h> Thanks. |
Problem solved:
Code:
#include <stdio.h> Very interesting program, how ever did you stumble across it? I did'nt even now you could declare variables like that, It represents the type of int (*p)[5] which should be 5 values of evaluated int* addresses. C is really something isn't it? |
I found it in a exercise of a book(C Programming:A modern approach). I can't find any answer to this problem... I guess I'm still a newbie. And yes, I'm learning new things in C everyday.
|
Quote:
The code I posetd is the answer. The type you should use is: int (*x(int i))[5] Nice book. Try Kernigan and Richie. That's what we study at the Computer Science Faculty |
Rajahuroman's version gives an error under -Wall because the return statement in x returns an int while x is, I think, declared to return a pointer to array of 5 ints. Here's one that compiles without warnings:
Code:
#include <stdio.h> In short, x() is declared to be a function which takes an integer argument and returns a pointer to int, with the information that there are 5 integers starting at the spot to which the pointer points. Because the compiler sees *p as an array and not just an integer, (*p) can be indexed with []. At least, that's what I guess after playing with a debugger on it. it's definitely some obscure C. |
Thanks for your help. I'm trying to learn C by myself I've a long way to go. Again thanks.
|
Quote:
|
All times are GMT -5. The time now is 09:40 AM. |