&arr
gives an array pointer, a special pointer typeint(*)[5]
which points at the array as whole.arr
, when written in an expression such aint *q = arr;
, “decays” into a pointer to the first element. Completely equivalent toint *q = &arr[0];
In the first case you try to assign a int(*)[5]
to a int*
. These are incompatible pointer types, hence the compiler diagnostic message.
As it turns out, the array pointer and the int pointer to the first element will very likely have the same representation and the same address internally. This is why the first example “works” even though it is not correct C.
Related Posts:
- What does ** do in C language?
- Difference between char *argv[] and char **argv for the second argument to main()
- char *array and char array[]
- C pointers and arrays: [Warning] assignment makes pointer from integer without a cast
- “error: assignment to expression with array type error” when I assign a struct field (C)
- Getting “conflicting types for function” in C, why?
- Getting “conflicting types for function” in C, why?
- How do I create an array of strings in C?
- How to make an array with a dynamic size? General usage of dynamic arrays (maybe pointers too)?
- How to create an array of strings in C?
- Returning an array using C
- What is the difference between char array and char pointer in C?
- Excess elements of scalar initializer for pointer to array of ints
- How can I find the number of elements in an array?
- Array type char[] is not assignable
- Parameter name omitted error?
- C char array initialization
- Dynamic vs static array in c
- Warning: comparison of distinct pointer types
- The difference between char * and char[] [duplicate]
- Pointer to 2D arrays in C
- GCC: Array type has incomplete element type
- variably modified array at file scope in C
- How to split a string into an array in Bash?
- Arrow operator (->) usage in C
- What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it?
- Pointer Arithmetic
- What does “dereferencing” a pointer mean?
- How do I create an array of strings in C?
- Java Error “Exception in thread “main” java.util.InputMismatchException” On an Array program
- “Expected expression before ‘ { ‘ token”
- How to print the array?
- Does JavaScript have a method like “range()” to generate a range within the supplied bounds?
- Does JavaScript have a method like “range()” to generate a range within the supplied bounds?
- How do you make an array of structs in C?
- Form submission: PHP S_SESSION statements within a foreach loop
- Working with a List of Lists in Java
- What is the difference between const int*, const int * const, and int const *?
- Array Size (Length) in C#
- How to convert jsonString to JSONObject in Java
- Is there a function to copy an array in C/C++?
- Passing by reference in C
- what does “>>>” mean in java?
- Why does the arrow (->) operator in C exist?
- Calculating Standard Deviation & Variance in C++
- How do I create an array of strings in C?
- Passing a 2D array to a C++ function
- Why am I getting “array initializer must be an initializer list or string literal”?
- What is a list in Bash?
- When will the worst case of Merge Sort occur?
- #31 expression must have integral type
- How do you pass a function as a parameter in C?
- Invalid pointer error on invoking free() after malloc in C
- expression must have integral type
- How do you pass a function as a parameter in C?
- ow to create a histogram in java
- expression must have integral type
- How do you pass a function as a parameter in C?
- C free(): invalid pointer
- what does .space do in mips?
- What’s wrong with my code? What is argv[1]?
- Delete 2D array C++
- Reversing a string in C
- Warning: assignment from incompatible pointer type
- Why am I getting this error: “data definition has no type or storage class”?
- Typedef function pointer?
- I’m getting “Invalid Initializer”, what am I doing wrong?
- Bubble sort algorithm in MIPS
- Error: unsupported use of matrix or array for column indexing
- Convert char array to string use C
- warning: passing argument ’from incompatible pointer type [enabled by default]’
- Iterate through a C array
- Using multiple variables in a for loop in Python
- Weighted random selection from array
- How to convert const char* to char* in C?
- How to copy a char array in C?
- Why do I get “cast from pointer to integer of different size” error?
- C subscripted value is neither array nor pointer nor vector when assigning an array element value
- struct has no member named
- java.lang.ArrayIndexOutOfBoundsException: 4 Error
- How to empty a char array?
- What does ** mean in C?
- How to sort an array in Bash
- What exactly is meant by “de-referencing a NULL pointer”?
- Casting a pointer to an int
- C++ Array of pointers: delete or delete []?
- How to allocate array of pointers for strings by malloc in C?
- How to declare and use 1D and 2D byte arrays in Verilog?
- Array to Hash Ruby
- Dereference void pointer
- Print array elements on separate lines in Bash?
- Java says this method has a constructor name
- Is C++ Array passed by reference or by pointer?
- What is the best way to delete a value from an array in Perl?
- How do I check if a string contains a certain character?
- Using pointer to char array, values in that array can be accessed?
- Numpy matrix to array
- Using the Pythagorean theorem with Java
- Array of Linked Lists C++
- lvalue required as increment operand