James already answered the particulars of your question - consider this some additional information.
Declarations in C are based on the types of expressions, not objects. If you have an array of integers and you want to access the i
'th integer, you would write
x = arr[i];
The type of the expression arr[i]
is int
, so the declaration of arr
is written as
int arr[N]; // arr is an N-element array of int
Similar logic applies to pointer declarations; if you have a pointer to a double
and you want to access the pointed-to value, you'd write
y = *p;
The type of the expression *p
is double
, so the declaration of p
is written as
double *p;
Same for function declarations; you call a function that returns an integer as
x = f();
The type of the expression f()
is int
, so the declaration of the function is written as
int f( void ); // void means the function takes no parameters
C declaration syntax uses something called a declarator to specify an object's array-ness, pointer-ness, or function-ness. For example:
int x, arr[10], *p, f(void);
declares x
as a plain int
, arr
as a 10-element array of int
, p
as a pointer to an int
, and f
as function taking no parameters and returning int
.
You'll occasionally see pointer declarations written as T* p
, however they will be parsed as T (*p)
; the *
is always part of the declarator, not the type specifier.
C declaration syntax allows you to create some pretty complex types in a compact format, such as
int *(*(*f[N])(void))[M];
In this declaration, f
is an N-element array of pointers to functions returning pointers to M-element arrays of pointers to int
.
In your declaration
int beepData[] = {1200, 100};
beepData
is being declared as an array of an unknown size; the size is taken from the number of elements in the initializer {1200, 100}
, in this case 2.
I know nothing about Swift, so I wouldn't know how to translate the C code to it. The best I can do is explain how the C code works.