Interacting with the System and Managing Memory

Original Course link: Interacting with the System and Managing Memory Module 2: Dynamic allocation most of the memory we have used has been located on the stack. Dynamic memory allocation gives a programmer much more flexibility, in that it allows you to request a specific amount memory to be allocated on the heap, so that it will not disappear with the stack frame of the calling function. heap vs. stack Stack vs Heap: What’s the difference? (educative.io) ...

2024-8-23 · 7 min · Atom.X

42 School - shell00/ C

shell shebang line (#!/bin/bash to tell the system which interpreter to use special or wired file name delimeter \ tab, to show the special or wired file name such as : % touch "23\\?\$*'MaRViN'*$?77&\\" -rw-r--r-- 1 linxu 2024_heilbronn 0 Jan 17 21:20 \?$*'MaRViN'*0\ % rm \\\?\$\*\'MaRViN\'\*0\\ # input \ and then click tab, the terminal will show us \\?\$\*\'MaRViN\'\*0\\ automatically, # for us to confirm it automatically. % ls -lRa *MaRV* | cat -e -rw-r--r-- 1 linxu 2024_heilbronn 3 Jan 17 21:51 "\?$*MaRViN*$?\"$ # the file size 3, it is wrong, use echo and terminator % to end the input % echo -n 42 > \"\\\?\$\*MaRViN\*\$\?\\\" % cat \"\\\?\$\*MaRViN\*\$\?\\\" 42% # The function of the % mark is to indicate that the prompt is on the same line as the output, # because there is no linefeed character at the end of the output. This can help you distinguish # between the output and the prompt, and avoid confusion. However, some shells may use different # symbols or colors to indicate this situation. man how to modify the file size, time, dates, link number, in terminal unix. how to use and read command manual. ...

2024-1-15 · 8 min · Atom.X

Multidimensional Arrays

Week 3, Multidimensional Arrays Incompatible Representations C语言中多维数组中不兼容表示 参考更多案例: github/c3w3_1.segmentation_fault.c github/c3w3_1.compiler_wrong.c #include <stdio.h> void printArray(int (*arr)[5], int rows) { for (int i = 0; i < rows; ++i) { for (int j = 0; j < 5; ++j) { printf("%d ", arr[i][j]); } printf("\n"); } } int main() { int twoDArray[3][5] = { {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15} }; // 这将有效,因为函数期望一个指向包含5个整数的数组的指针 printArray(twoDArray, 3); return 0; }

2023-12-12 · 1 min · Atom.X

Pointers, Arrays, and Recursion 2

Week 2, Read pointer 2 #include <stdio.h> #include <stdlib.h> int f(int **r, **s){ int temp = **r; int temp2 = **s; int *z = *r; *r = *s; *s = z; printf("**r = %d\n",**r); printf("**s = %d\n",**s); *z += 3; **s -= 8; **r -= 19; return temp + temp2; } int main(void) { int a = 80; int b = 12; int * p = &a; int * q = &b; int x = f(&p, &q); printf("x = %d\n", x); printf("*p = %d\n", *p); printf("*q = %d\n", *q); printf("a = %d\n", a); printf("b = %d\n", b); return EXIT_SUCCESS; } Output **r = 12 **s = 80 x = 92 *p = -7 *q = 75 a = 75 b = -7 ...

2023-12-11 · 1 min · Atom.X

Pointers, Arrays, and Recursion 1

Original Course link: Pointers, Arrays, and Recursion Week 1, Read pointer 1 C pointer C语言指针详解,30分钟玩转C语言指针 (biancheng.net) C语言指针变量的定义和使用(精华)_54笨鸟 (54benniao.com) #include <stdio.h> #include <stdlib.h> void g(int x, int * y) { printf("In g, x = %d, *y = %d\n", x, *y); x++; *y = *y - x; y = &x; } void f(int * a, int b) { printf("In f, *a = %d, b = %d\n", *a, b); *a += b; b *= 2; // * multiply, not pointer identifier here; g(*a, &b); printf("Back in f, *a = %d, b = %d\n", *a, b); } int main(void) { int x = 3; int y = 4; f(&x, y); printf("In main: x = %d, y = %d\n", x, y); return EXIT_SUCCESS; } Output In f, *a = 3, b = 4 In g, x = 7, *y = 8 Back in f, *a = 7, b = 0 In main: x = 7, y = 4 ...

2023-12-10 · 2 min · Atom.X