Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void by_value(const T* array) // const T array[] means the same
- void by_pointer(const T (*array)[U])
- void by_reference(const T (&array)[U])
- const int a[] = { 2, 3, 5, 7, 11 };
- const int* p = a;
- assert( sizeof(p) != sizeof(a) ); // sizes are not equal
- char a[80];
- strcpy(a, "This is a test");
- char *strcpy(char *dest, const char *src);
- char a[80];
- char *ptr_to_first_element = a;
- char (*ptr_to_array)[80] = &a;
- a[i] == ptr_to_first_element[i] == (*ptr_to_array)[i] != *ptr_to_array[i] != ptr_to_array[i]
- sizeof a == sizeof *ptr_to_array == 80
- sizeof *ptr_to_first_element == sizeof (char) == 1
- sizeof ptr_to_first_element == sizeof (char *) == whatever the pointer size
- is on your platform
- void foo(int arr[]);
- int arr[5];
- int *ip = &(arr[1]);
- if (arr == ip) { /* something; */ }
- arr[42];
- /* same as *(arr + 42); */
- /* same as *(&(arr[0]) + 42); */
- void do_something(int *array) {
- // We don't know how big array is here, because it's decayed to a pointer.
- printf("%in", sizeof(array)); // always prints 4 on a 32-bit machine
- }
- int main (int argc, char **argv) {
- int a[10];
- int b[20];
- int *c;
- printf("%zun", sizeof(a)); //prints 40 on a 32-bit machine
- printf("%zun", sizeof(b)); //prints 80 on a 32-bit machine
- printf("%zun", sizeof(c)); //prints 4 on a 32-bit machine
- do_something(a);
- do_something(b);
- do_something(c);
- }
- void do_something(int array[][10])
- {
- // We don't know how big the first dimension is.
- }
- int main(int argc, char *argv[]) {
- int a[5][10];
- int b[20][10];
- do_something(a);
- do_something(b);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement