From e20ac23baa98906ea7f8407aaa230b11386b5030 Mon Sep 17 00:00:00 2001 From: Jet Hughes Date: Thu, 11 Aug 2022 11:19:21 +1200 Subject: [PATCH] vault backup: 2022-08-11 11:19:21 --- .../notes/10-intro-to-c-arrays-malloc-free.md | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/content/notes/10-intro-to-c-arrays-malloc-free.md b/content/notes/10-intro-to-c-arrays-malloc-free.md index 90f453a16..82325ad67 100644 --- a/content/notes/10-intro-to-c-arrays-malloc-free.md +++ b/content/notes/10-intro-to-c-arrays-malloc-free.md @@ -11,6 +11,8 @@ tags: ``` c uint32_t array[10]; float matrix[5][6]; +double balance[5] = {1000.0, 2.0, 3.4} //last two elementes will be initalised to zero +double balance[] = {1000.0, 2.0, 3.4} //size is calculated automatically ``` - do not have methods @@ -21,10 +23,32 @@ float matrix[5][6]; - 'H' 'e' 'l' 'l' 'o' '\0' <- sentinel value ``` c -char *check = thing; +//find the length of an array +size_t strlen(const char *of){ + char *check = of; + + while(*check != '\0') + check++; + + return check - of; +} +``` -while(*check != '\0') - check++ +# quoted strings +- "Hello World" +- must be const - not allowed to change them + - `const char *hello_world = "hello world"` +- can use then in place of char arrays + +# Memory +when we decalre an array we are saying "choose somewhere in memory to put this number of that and call it thing" + +```c +that thing[this]; + +uint_t byte_array[1024]; +``` + +- compiler chooses somewhere in memory +- the name of the array maps to the location -length = check - thing -``` \ No newline at end of file