Please enable JavaScript.
Coggle requires JavaScript to display documents.
C array (Multi-dimension aray (:red_flag: int a[2][3] = {1, 2, 3, 4, 5}; …
C array
Multi-dimension aray
:red_flag:
int a[2][3] = {1, 2, 3, 4, 5};
equals
int a[2][3] = {{1, 2, 3}, {4, 5, 0}}
:warning:BUT
int a[2][3] = {{1, 2, 3, 4, 5}};
equals
int a[2][3] = {{1, 2, 3}, {0, 0, 0}}
CAN init an array to all zeros like this
int a[2][3] = {0};
static VS dynamic array
Static array
be allocated at compile time
must
provide the array size
Dynamic array
be allocated at run time
no need
to provide the array size;
often implemented as a pointer use malloc/new
Terms
Jagged Array
Is an array that each element is an array
Command line argument
int argc
number of input CMD parameters
number of parameters >= 1
Since argv[0] is the name of the executable
char *argv[]
vector of input parameters
always has at least 1 element
argv[0]
,
which is the name of the executable
Usage:
E.g. GIT, GCC
Confusing things
:warning:
Pointer to Array VS Array of pointer
int (*a)[7];
is a pointer to an array
int *a[7];
or
int\ *(a[7]);
is an array of pointers
Note
char str[] = "hi"; //is OK
BUT
char str[2];
str = "hi";
//got ERROR
???
https://www.sanfoundry.com/c-mcq-multidimensional-arrays/
https://www.sanfoundry.com/c-quiz-questions-initialization-pointer-arrays/
https://www.sanfoundry.com/c-programming-questions-answers-pointers-vs-multi-dimensional-arrays-2/
https://www.sanfoundry.com/c-question-bank-complicated-declarations/