1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
#include <stdio.h>

int strlen(char* s) { // returns the length of the string, not including the '\0'
    // expect about 2-6 lines of code here






}

int main(int argc, char *argv[]) {

    // A string is an array of characters.
    // A string literal ("...") automatically has a '\0' appended to it.
    // '\0' is called the null terminator, and its value is 0.
    char s1[3]; // declare array of 3 characters
    //s1[0] = "H";  // BAD
    s1[0] = 'H';    // GOOD
    s1[1] = 'i';
    s1[2] = '\0'; // without this, we would have bugs
    char s3[] = "Hi"; // you don't need to add the '\0' when using "..."
    char* s4 =  "Hi"; // s4 is the address of the first character, 'H'
    char s2[] = {'H',   'i', '\0'};
    char s6[] = {0x48, 0x69, 0x00};
    char s5[] = {72,    105,    0};
    char s7[] = {72,   1105,    0};

    return 0;
}

This content is protected and may not be shared, uploaded, or distributed.    © 2019 Alexander J. Quinn.