Hi There!

I'm Dan Schlegel, an Associate Professor in the Computer Science Department at SUNY Oswego

Class Code 2/8/19

#include 
#include 

struct person {
    char name[50];
    int age;
};

void capFirst(char str[]){
    str[0] -= 32;
}

void a(int i, int j){
    printf("i: %d j: %d", i, j);
}

int* dontdothis(){
    int i = 4;
    return &i;
}

void someotherfun(){
    int i = 23;
}


int main() {
    printf("Hello, World!\n");

//    int *ip = malloc(sizeof(int));
//    *ip = 5;
//
//    a(*ip, 3);

    char str1[] = "hello";
    printf("%s\n", str1);
    capFirst(str1);
    printf("%s\n", str1);

    char *str2 = malloc(sizeof(char) * 6);
    strcpy(str2, "hello");
    printf("%s\n", str2);
    capFirst(str2);
    printf("%s\n", str2);

    printf("%c\n", str2[3]);
    printf("%c\n", (*str2+3)); // pointer arithmetic
    printf("%p\n", (str2+3)); // printing the pointer itself

    int* pi = dontdothis();
    printf("pi: %d\n", *pi);

    someotherfun();
    printf("pi: %d\n", *pi);

    // Illustating writing past the bounds of the array, not using null terminator.
    char* a1 = malloc(sizeof(char));
    a1[0] = 'a';
    a1[1] = 'b';
    printf("a1: %s\n", a1);
    free(a1);
    //a1 = NULL; // Always set to null after freeing, otherwise you have a dangling pointer.
    printf("a1: %s\n", a1);

    // a2 is allocated at the same spot a1 was.
    char* a2 = malloc(sizeof(char));
    //a2[0] = 'c';
    printf("a2: %s\n", a2);

    // Making a 2d array
    int** arr2d = malloc(sizeof(int*) * 4);
    for ( int i = 0; i < 4; i++ ){
        arr2d[i] = malloc(sizeof(int) * 4);
    }


    return 0;
}