Strings in C
· β˜• 3 min read · ✍️ Ben Mason
Strings (c and c++) Strings are an array of characters * they are accessed using the address of the first character (item) in the array A String is an array of characters ending in a null character \0 char color[] = β€œblue”; // 5 Char array continaing 'b', 'l', 'u', 'e', '\0' char *colorPtr = β€œblue”; // pointer to memory location constinaing 'blue' don’t forget to size arrays to hold the null character if explicitly defining array length C++ String Read functions Collect unlimited Characters until space, tab or EOL cin >> word;

Pointers in C / C++
· β˜• 7 min read · ✍️ Ben Mason
Pointers (c and c++) The Basics and Pitfalls of Pointers in C | Hackaday single indirection Define a Pointer int *intPtr * – indirection operator or de-referencing operator &varable – Memory address to variable *intPtr – De-reference pointer (indirection), pull literal value located at the memory address of the pointer Pointer Example // Declare Variable int value1 = 5000; // Declare 3 pointers int *ptr1; int *ptr2; int *ptr3; // Assign address of variable to ptr1 ptr1 = &value1; // Assign address of ptr1 to ptr2 then ptr2 to ptr3 ptr2 = ptr1; ptr3 = ptr2; // Print literal value stored in value1 printf("value1: %d\n\r", value1); printf("ptr1: %d\n\r", *ptr1); printf("ptr2: %d\n\r", *ptr2); printf("ptr3: %d\n\r", *ptr3); /* Output value1: 5000 ptr1: 5000 ptr2: 5000 ptr3: 5000 */ // Set Literal value to the memory address in ptr3, setting the value of value1 to 4000 *ptr3 = 4000; // Print literal values printf("\n\rAssign 4000 to *ptr3\n\r"); printf("value1: %d\n\r", value1); printf("ptr1: %d\n\r", *ptr1); printf("ptr2: %d\n\r", *ptr2); printf("ptr3: %d\n\r", *ptr3); /* Output: Assign 4000 to *ptr3 value1: 4000 ptr1: 4000 ptr2: 4000 ptr3: 4000 */ Pointer Math Adding 1 to will increment the pointer address the size of the value type (ie int, char etc)