Commit ad982dc2 authored by Autopawn's avatar Autopawn

Renamed le07_encap as leX6. Added small parts to other lectures.

parent 9c04f621
......@@ -171,7 +171,7 @@ ptrs[2] = &a;
:arrow_right: It is associated to a **size**, modern languages store it within the array but C **doens't**.
:arrow_right: They are identified with a **pointer** to the position of the **first** element.
:star: In some languages a check in runtime if an index is within the range of the array.
:star: Some languages check in runtime if an index is within the range of the array.
:star: Some languages provide multidimensional arrays.
---
......@@ -1002,4 +1002,38 @@ Programming languages are distinguished by the following **features**:
---
![center w:500](humor/programming_language_deep.jpg)
\ No newline at end of file
![center w:500](humor/programming_language_deep.jpg)
---
# Automatic variable initialization
:arrow_right: If a variable is not initialized in C, then it will aquire whatever value was at that position in memory.
:skull: If the value is used before being initialized/assigned this means **undefined behaviour**.
:arrow_right: In modern programming languages, variables are initialized by default to $0$ or the equivalent (this has a little *overhead*).
---
```c
#include <stdio.h>
int f(){
int x = 3;
return x;
}
int g(){
int y; //uninitialized y
printf("y: %d\n",y);
}
int main(){
f();
g();
}
```
```plain
y: 3
```
\ No newline at end of file
......@@ -234,4 +234,39 @@ z:4
# Sobreescritura de operadores
:warning: Work in progress :warning:
\ No newline at end of file
:arrow_right: Lenguajes como C++ o Python permiten **sobreescribir** operadores para tipos de datos avanzados:
```python
class MyClass:
def __getitem__(self, key):
return key * 2
myobj = MyClass()
print(myobj[3])
```
```plain
6
```
:bulb: En estos lenguajes debemos esperar que al usar un operador se ejecute código arbitrario.
---
:arrow_forward: Otro ejemplo, con los arreglos de `numpy`:
```python
import numpy as np
a = [1,2,3,4]
b = [5,6,7,8]
print(a+b)
a = np.array([1,2,3,4])
b = np.array([5,6,7,8])
print(a+b) # Operator + overloaded for numpy arrays
```
```plain
[1, 2, 3, 4, 5, 6, 7, 8]
[ 6 8 10 12]
```
\ No newline at end of file
......@@ -179,7 +179,8 @@ Algunos lenguajes diferencian entre:
:warning: En JavaScript:
* El operador `===` compara **identidad**, si se trata de un **value type**, compara el **valor**.
* El operador `==` compara **igualdad**.
Y realiza conversión de tipos antes:bangbang: (es malvado :smiling_imp:).
Y realiza conversión de tipos antes:bangbang:
(es un ejemplo malvado de tipificado débil :smiling_imp:).
```javascript
var x = 2;
......
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