Actualizado el 21 de Marzo del 2018 (Publicado el 12 de Febrero del 2018)
545 visualizaciones desde el 12 de Febrero del 2018
1,0 MB
116 paginas
Creado hace 19a (01/11/2004)
INTRODUCCI ´ON AL LENGUAJE C
ACM Cap´ıtulo de Estudiantes
Facultad de Inform´atica, UPM
Noviembre 2004
Introducci´on al lenguaje C
c(cid:13)2003-2004 ACM Cap´ıtulo de Estudiantes - Facultad de Inform´atica UPM
ACM Cap´ıtulo de Estudiantes
Facultad de Inform´atica - Universidad Polit´ecnica de Madrid
Campus de Montegancedo s/n
28660 Boadilla del Monte
MADRID (SPAIN)
Esta obra puede ser distribuida ´unicamente bajo los t´erminos y condiciones expuestos en Creative Commons
Reconocimiento-CompartirIgual 2.0 o superior (puede consultarla en http://creativecommons.org/licenses/by-sa/2.0/es/).
´Indice general
1. Introducci´on
1.1. Un poco de historia...
1.2. Caracter´ısticas . . .
1.3. C frente a C++ . .
. . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . .
. . .
. . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . .
. . .
. . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . .
. . .
. . .
. . . .
. . . .
. . . .
2. Herramientas y software para la programaci ´on en C (entorno GNU/Linux)
2.1. Compilador: gcc .
2.2. Depuradores: gdb y ddd .
. . . .
. . . .
. . . .
. . . .
2.1.1. Manejo de gcc . .
. . . .
. . . .
2.1.2. Warnings y errores . . . .
. . . .
2.1.3. Opciones m´as comunes . .
. . . .
. . . .
. . . .
2.2.1. Depurando con gdb . . .
. . . .
2.2.2. Depurador gr´afico: ddd .
. . . .
2.2.3. Manejo . .
. . . .
. . . .
2.3. Control de dependencias: make .
2.4. Manuales: man . .
. . . .
. . . .
2.5. Control Concurrente de Versiones: cvs .
. . . .
. . . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
2.6. Herramientas de desarrollo C sobre Windows .
. . .
2.5.1. Escenario de uso .
2.5.2. Manejo . .
. . . .
2.6.1. GCC en Windows
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
3. Introducci´on al lenguaje C. Sintaxis
3.3. Constantes .
3.4. Operadores
. . . .
. . . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
3.2.1. Tipos de datos
. .
3.2.2. Calificadores . . .
3.2.3. Variables .
. . . .
. . . .
. . . .
3.1. Estructura de un programa simple en C . .
. . . .
3.2. Tipos b´asicos . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
3.3.1. Constantes num´ericas . . .
. . . .
3.3.2. Constantes de caracteres .
. . . .
3.3.3. Constantes enumeradas . .
3.3.4. Uso del preprocesador para definir constantes simb´olicas . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
3.4.1. Operadores aritm´eticos . .
3.4.2. Operadores relacionales
.
3.4.3. Operadores l´ogicos . . . .
3.4.4. Operadores a nivel de bit (bitwise operators)
3.4.5. Operadores especiales
. . . .
3.4.6. Precedencia de operadores . . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
3.5. Estructuras de control . . .
. . . .
3.5.1. Sentencia if . . . .
. . . .
3.5.2. Sentencia if-else .
. . . .
3.5.3. Sentencia switch .
. . . .
3.5.4. Sentencia break . .
. . . .
3.5.5. Sentencia for
. . .
3.5.6. Sentencia while . .
. . . .
3.5.7. Sentencia do-while . . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
.
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . . .
. . . .
. . . .
. . . .
. . .
. . .
. . .
. . .
. .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
2
2
2
2
3
3
3
5
5
6
6
6
7
7
9
10
10
10
10
11
13
13
16
16
16
18
19
19
19
20
20
21
21
22
23
23
25
27
27
28
28
29
31
31
31
32
I
3.6. Funciones y subrutinas . .
. . . .
. . . .
. . .
. . . .
3.6.1. Paso de par´ametros a funciones. Llamadas por valor
3.7. Tipos de datos compuestos . . . .
. . . .
. . . .
. . . .
3.7.1. Arrays . . .
. . . .
3.7.2. Estructuras . . . .
3.7.3. Uniones . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . .
. . .
. . .
. . .
. . . .
. . . .
. . . .
. . . .
. . . .
.
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . .
. . .
. . .
. . .
. . .
. . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . .
. . .
. . .
. . .
. . .
. . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
4. El modelo de compilaci´on de C
. . . .
. . . .
4.1.
4.2. El preprocesador
Introducci ´on . . . .
.
. . . .
. . . .
4.2.1. #include: inclusi´on de otros ficheros . . . .
. . . .
4.2.2. #define: creaci´on de macros .
. . . .
. . . .
4.2.3. Compilaci´on condicional .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
4.3. Compilaci´on . . . .
. . . .
4.4. Enlazado .
. . . .
. . . .
4.5. Un ejemplo sencillo . . . .
. . .
. . .
. . .
. . .
. . .
. . . .
. . . .
. . .
. . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
5. Punteros
. . . .
5.1.
. . . .
. . . .
. . . .
. . . .
. .
. . . .
. . . .
. . . .
. . . .
5.2. Sint´axis de punteros . . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
Introducci ´on . . . .
5.1.1.
5.1.2.
5.3. Strings . . .
5.4. Aritm´etica de punteros
5.5. Estructuras y punteros . . .
5.5.1. El operador “->” .
5.6. Memoria din´amica . . . .
. . . .
. . . .
5.4.1. Contexto .
. . . .
5.4.2. Tipos de operaciones . . .
5.4.3. Ejemplos de aritm´etica . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
5.6.1.
¿Qu´e es la memoria din´amica? . .
5.6.2. El mapa de memoria en Unix . . .
. . . .
5.6.3. Primitivas b´asicas .
. . . .
. . . .
. . . .
. . . .
5.7. Arrays y punteros .
. . . .
. . . .
. . . .
5.7.1. Repaso . .
. . . .
. . . .
5.7.2.
Introducci ´on . . .
. . . .
Indirecciones m´ultiples . .
. . . .
. . . .
. . . .
5.8.1. Declaraci´on . . . .
. . . .
. . . .
5.8.2. Utilizaci´on . . . .
. . . .
5.8.3. Ejemplos de uso .
. . . .
5.8.4. Cadenas enlazadas . . . .
. . . .
. .
.
. . .
. . . .
¿Qu´e es un puntero? . . .
. . .
¿Para qu´e necesito yo un puntero? . . .
. . .
. . .
. . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
5.2.1. Declaraci´on de punteros .
5.2.2. Punteros gen´ericos . . . .
. . . .
5.2.3. Los operadores de contenido “*” y de indirecci´on “&” . . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . .
. . . .
5.10.1. Comparaci´on de punteros a cadenas . .
. . . .
. .
5.10.2. Punteros “a Roma” (memory leaks)
. . . .
. . .
. . . .
5.10.3. Doble liberaci´on .
. . . .
. . . .
5.10.4. Usar : en lugar de -> . . .
. . . .
. . .
5.10.5. Operar con los punteros en lugar de con los contenidos . . . .
5.10.6. Finalizaci´on de cadenas
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
¿Qu´e es el paso por referencia?
. . . .
¿Para qu´e necesito el paso por referencia? . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
5.9. Paso por referencia vs. paso por valor
5.10. Erro
Comentarios de: Introducción al Lenguaje C (0)
No hay comentarios