To install click the Add extension button. That's it.

The source code for the WIKI 2 extension is being checked by specialists of the Mozilla Foundation, Google, and Apple. You could also do it yourself at any point in time.

4,5
Kelly Slayton
Congratulations on this excellent venture… what a great idea!
Alexander Grigorievskiy
I use WIKI 2 every day and almost forgot how the original Wikipedia looks like.
Live Statistics
Spanish Articles
Improved in 24 Hours
Added in 24 Hours
Languages
Recent
Show all languages
What we do. Every page goes through several hundred of perfecting techniques; in live mode. Quite the same Wikipedia. Just better.
.
Leo
Newton
Brights
Milds

De Wikipedia, la enciclopedia libre

typedef es una palabra reservada en el lenguaje de programación C y C++. Su función es asignar un nombre alternativo a tipos existentes, a menudo cuando su declaración normal es aparatosa, potencialmente confusa o probablemente variable de una implementación a otra.

YouTube Encyclopedic

  • 1/3
    Views:
    31 683
    24 102
    11 464
  • C Programming Tutorial 45, Typedef Keyword
  • Typedef() in C (HINDI/URDU)
  • typedef in C Part-1 | C Language Tutorial

Transcription

Ejemplos de uso

Ejemplo básico de typedef

Considere este código:

#include <stdio.h>

int main(void)
{
    int notas;
    notas=100;
    return 0;
}

Ahora considere esto :

#include <stdio.h>

int main()
{
    typedef int nota_alumno_t;
    nota_alumno_t notas;
    notas=100;
    return -1;
}

Ambas secciones de código hacen lo mismo: crean un tipo int (notas) y le dan un valor de 100. El método para hacer esto en la segunda sección hace que sea más legible porque la declaración typedef hace que nota_alumno_t signifique lo mismo que int. En este ejemplo, la variable notas guarda las "notas" de un estudiante, así que definir notas como una variable de tipo nota_alumno_t le da al nombre de esa variable un contexto.

Ejemplo con struct

Un ejemplo más:

struct var
{
   int data1;
   int data2;
   char data3;
};

Aquí, un tipo var ha sido definido por el usuario. Así que para crear una variable de tipo var, usamos este código:

struct var a;

Agreguemos esta línea o no:

typedef struct var nuevotipo;

Ahora, para crear una variable de tipo var, alcanza con:

nuevotipo a;

Esto es más legible porque no se requiere la palabra reservada struct antes de cada variable de tipo var.

Uso en C++

std::vector<std::pair<std::string, int> > valores;
for (std::vector<std::pair<std::string, int> >::const_iterator i = valores.begin(); i != valores.end(); ++i)
{
   std::pair<std::string, int> const & t = *i;
   // hacer alguna tarea
}

y

typedef std::pair<std::string, int> valor_t;
typedef std::vector<valor_t> valores_t;

valores_t valores;
for (valores_t::const_iterator i = valores.begin(); i != valores.end(); ++i)
{
   valor_t const & t = *i;
   // hacer alguna tarea
}

Enlaces externos

Esta página se editó por última vez el 24 nov 2022 a las 18:27.
Basis of this page is in Wikipedia. Text is available under the CC BY-SA 3.0 Unported License. Non-text media are available under their specified licenses. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc. WIKI 2 is an independent company and has no affiliation with Wikimedia Foundation.