Please enable JavaScript.
Coggle requires JavaScript to display documents.
C programming (Pointer (Pointer errors (Pointer point to a un-init…
C programming
Pointer
Struct pointer
(*ptr).text.name = "duat"
same as ptr->name = "duat"
Array of pointers usage
store string array (char pointer)
[SORTING] swap value of 2 array members if want to swap 2 variables
SORTING of string, struct
Relationship with array
Array name = cannot changed address
pointer + array + literal
char str[] = "hi"
"hi" is copied to allocated memory of str
char *str = "hi"
str points to addr that stores "hi"
pointer + malloc + literal
char
str;
str = (char
)malloc(100); // (1)
str = "hi"; // (2)
free(str); // (3) error
(1) str points to heap
(2) str points to data segment (read-only)
(3) cannot free a read-only location
2 types of pointers
typed pointer
char, int, struct,..
not-typed/generic pointer
void
Why pointer is invented?
Pointer errors
Pointer point to a un-init variable
null pointer
Deference an un-init pointer
Pointer point to an de-allocated memory
Terms
Memory map IO = access IO via memory addr
Variable name is store
not in memory
in compiler's symbol table
is a compile time data structure
Makefile
Group of gcc command
Syntax:
output: input1 input2
<1 tab> gcc_commands
Keywords
volatile
Usecases
global var that accessed by ISR
var used in multi thread
Memory-mapped peripheral registers
Text file processing
Standard I/O
puts & gets
print/read a string
putc & getc/getchar
print/read a character
printf & scanf
print/read formatted output/input
Text file
fputs & fgets
print string to a file/ read string from a file
fputc & fgetc
print char to a file/ read char from a file
fprintf & fscanf
print formatted output to a file/ read formatted input from a file
fopen & fclose
open/close a text file
feof
detect end-of-file marker in a file
Operator
Operator precedence
Right-to-left-operator
Assignment operator
=
+= or -= or *= or /= or %=
<<= or >>=
&= or ^= or |=
++ or --
unary + -
! ~
&
(typecast), sizeof
A lot of left-to-right operators
Comparisons
Declaration
typedef VS #define
Misc
Risk of no func prototype
Compiler
only show warnings
when the no of params
mismatches
with the func arguments
May cause no error, but wrong processing