C: Pointers

Mi'kail Eli'yah
2 min readApr 29, 2024

Using pointers is a means to access data or memory regions directly.

Test usages for different test cases:

test_usages_00.c

test_usage_choosing_function_at_runtime()
test_usage_reading_addresses()
test_usage_passing_pointer_as_argument()
test_usage_pointer_trials()
test_usage_check_if_agnostic_function_is_designated(){
test_usage_write_data_to_specific_memory_regions()

test_usages_02.c

test_usage_passing_array_and_pointer()

There are ways to fetch data by specifying the data length and format it has to fit into.

    long i = 0;
float y = 5115.00005;
i = * (long* ) &y; // to point to a memory to obtain without truncation
y = * (float* ) &i; // get the value from the memory
printf("%f \n", y);


/*

*/
#include <stdio.h>
#define GPIO_A 0xaabbccdd
#define GPIO_B 0x11223344

int main() {
char *p_c;
int *p_i;
p_c = (char*) GPIO_A;
p_i = (int*) GPIO_B;

printf("%x \n", p_i + sizeof(int)); // 11223354
printf("%x, %x \n", p_c++, p_i++); // aabbccdd, 11223344
printf("%x, %x \n", p_c, p_i); // aabbccde, 11223348

return 0;
}
example of pointer pointing to a structure, e.g. to access ODR: GPIOA -> ODR |= 1UL << 5;
//
#include <stdio.h>
#include <stdint.h>

// Define GPIO register addresses (example values)
#define GPIO_A_ADDR 0x40020000 // Assume GPIO_A starts at this address
#define…

--

--

Mi'kail Eli'yah
Mi'kail Eli'yah

No responses yet