Commit 4249cde4 authored by xingqiao's avatar xingqiao
Browse files

helloworld basic code files

parent 7f09aded
#include <stdio.h>
#include <stdlib.h>
// global static memory
char char1;
int int1;
double arr1[2];
int main(void) {
// local stack memory
char char2;
int int2;
float arr2[2];
// manually allocated heap memory
void *mem = malloc(1);
printf("%p\n", (void *)&char1);
printf("%p\n", (void *)&int1);
long difference1 = (long)&int1 - (long)&char1;
printf("%ld\n", difference1);
printf("%ld\n", (long)&char1 - (long)&int1);
printf("%p\n", (void *)&arr1);
printf("%p\n", (void *)&arr1[0]);
printf("%p\n", (void *)&arr1[1]);
long difference2 = (long)&arr1[1] - (long)&arr1[0];
printf("%ld\n", difference2);
long difference3 = &arr1[1] - &arr1[0];
printf("%ld\n", difference3);
printf("%ld\n", (long)&arr1[1] - (long)&arr1[0]);
printf("%ld\n", &arr1[1] - &arr1[0]);
printf("%p\n", (void *)&char2);
printf("%p\n", (void *)&int2);
printf("%ld\n", (long)&int2 - (long)&char2);
printf("%p\n", (void *)&arr2);
printf("%p\n", (void *)&mem);
printf("%p\n", (void *)&arr2[0]);
printf("%p\n", (void *)&arr2[1]);
printf("%ld\n", (long)&arr2[1] - (long)&arr2[0]);
printf("%ld\n", &arr2[1] - &arr2[0]);
printf("%p\n", mem);
free(mem);
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment