Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions lesson_01/arrays.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,29 @@ int main() {
printf("void pointer to array: %p\n", void_pointer_to_values);

// imprime cuantos bytes ocupa un entero en el sistema actual
printf("size of interger %d\n", sizeof(int));
printf("size of interger %lu\n", sizeof(int));
// Regresa el numero de bytes que ocupa el arreglo completo
printf("size of array: %d\n", sizeof(values));
printf("size of array: %lu\n", sizeof(values));
// Regresa el numero de bytes que ocupa una direccion de memoria
// en la computadora donde se ejecuta
printf("size of array through pointer: %d\n", sizeof(pointer_to_values) );
printf("size of array through pointer: %lu\n", sizeof(pointer_to_values) );

// Aritmetica de apuntadores, *(values + 2) == values[2]
printf("pointer: %p, pointer + 2: %p\n", values, values + 2);
printf("pointer at position 2: %p\n", &values[2]);
printf("value at position 2 %d\n", *(values + 2));
printf("value at position 2 %d\n", values[2]);

// Este arreglo lo creamos en el heap por medio de create_array
int* array_head = create_array();
printf("other array: %p\n", array_head);
// *array_head == *(array_head + 0) == array_head[0]
printf("other array value at 0: %d\n", *array_head);

// C no tiene garbage collector, por lo que la memoria que pedimos del Heap
// la tenemos que liberar explicitamente llamando la función free
// No vamos a utiliza realmente malloc durante el curso
free(array_head);
// la tenemos que liberar explicitamente llamando la función free
// No vamos a utiliza realmente malloc durante el curso
free(array_head);

return EXIT_SUCCESS; // 0 definido en stdlib
}
3 changes: 2 additions & 1 deletion lesson_01/struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void set_node_value(struct node* pointer_to_node, int new_value) {
// Es azucar sintactito de "(*pointer_to_node).value = new_value;"
}

// Paso por valor: se crea una copia del struct node
void set_node_value_wrong_way(struct node node, int new_value) {
node.value = new_value;
}
Expand Down Expand Up @@ -64,7 +65,7 @@ int main() {

// Esta es la cantidad de memoria que utiliza un struct node en
// la computadora donde ejecutamos este programa.
printf("sizeof(struct node) -> %d\n", sizeof(struct node));
printf("sizeof(struct node) -> %lu\n", sizeof(struct node));

// Asi creamos un "struct node" en el heap
struct node* other_node = create_node(8);
Expand Down
5 changes: 4 additions & 1 deletion lesson_02/preprocesor_directives.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <stdlib.h>
#include <assert.h>
#include <stdbool.h>
#include "list.h"
//#include "list.h"


/*
Expand All @@ -33,6 +33,9 @@
// inesperados, dado que no podemos garantizar que la presedencia de
// operadores se respete al hacer sustitucion textual
#define ADD(x, y) ((x) + (y))

// Observa que al remover estos paréntesis,
// la sustitución no se realiza de forma correcta
#define MULT(x, y) (x * (y))

/*
Expand Down
Loading