#include //standard input/output library #include //malloc() #include struct Student { char* name; int id; float gpa; }; void print_student (struct Student std){ printf("----------------------\n"); printf("Name: %s\n", std.name); printf("ID: %d\n", std.id); printf("GPA: %f\n", std.gpa); printf("----------------------\n"); } void foo1(int val){ //some code here... return; } void foo2(int* val){ //some code here... return; } void foo3(int** val){ //some code here... return; } void foo4(int*** val){ //some code code... return; } int main() { // //standard output/input // int value = 0; // printf("Enter a value: \n"); // scanf("%d", &value); // printf("The value you just entered is: %d\n", value); //struct // struct Student s; // s.name = "Roger"; // s.id = 9999999; // s.gpa = 4.0; // print_student(s); //pointers // int var = 20; // int* p1 = &var; // // //the statement above can be broken down into the following: // // int* p1; //declaration of a pointer // // //*p1 = &var; //not this one!!! // // p1 = &var; //initialize the pointer // int** p2 = &p1; // //print 20 // //int // printf("%d\n", var); // printf("%d\n", *p1); // printf("%d\n", **p2); // foo1(var); // foo1(*p1); // foo1(**p2); // //print addr of var // //int* // printf("%p\n", &var); // printf("%p\n", p1); // printf("%p\n", *p2); // foo2(&var); // foo2(p1); // foo2(*p2); // //print addr of p1 // printf("%p\n", &p1); // printf("%p\n", p2); // foo3(&p1); // foo3(p2); // //print addr of p2 // printf("%p\n", &p2); // foo4(&p2); //void pointers // int v = 100; // void* v_ptr = &v; // //option 1: // // int* ptr1 = v_ptr; // // printf("The value of v: %d\n", *ptr1); // //option 2: // printf("The value of v: %d\n", *((int*)v_ptr)); // v_ptr = &s; // struct Student * s_ptr = v_ptr; // print_student(*s_ptr); // print_student(*((struct Student*)v_ptr)); //stack vs. heap //malloc vs. free int* array = malloc(1000 * sizeof(int)); free(array); array = NULL; char* name = "Roger"; //constant string //name[0] = 'T'; for (int i = 0; i < strlen(name); ++i) { printf("%p\n", &name[i]); } char name2[6] = "Roger"; name2[0] = 'T'; printf("%s\n", name2); for (int i = 0; i < strlen(name2); ++i) { printf("%p\n", &name2[i]); } return 0; }