¡GoConqr estrena diseño! Cuéntanos qué te parece.

Apuntes

typedef

Anirudh pandey Computer Science Inglés 2 páginas

Contenido del apunte (2)

Página 1

Typedef

if We write program

#include <stdio.h>

int main(void)

{

struct node

{

int data;

struct node * next;

}node;

node *tmp;

tmp=( node *)malloc(sizeof(node));

scanf("%d",&tmp->data);

printf("%d",tmp->data);

// your code goes here

return 0;

}

it gives error

prog.c: In function ‘main’: prog.c:12:9: error: ‘tmp’ undeclared (first use in this function) node *tmp;

If I change declaration of tmp as

struct node * tmp;

then error gives

prog.c:14:14: error: expected expression before ‘)’ token tmp=( node *)malloc(sizeof(node));

Because typecasting is done with datatype and node * is not a datatype

So to make my own datatype we use typedef

and So a kind of program is and will remove both above two errors

#include <stdio.h>

int main(void)

{

typedef struct node

{

int data;

struct node * next;

}node;

node *tmp;

tmp=( node *)malloc(sizeof(node));

scanf("%d",&tmp->data);

printf("%d",tmp->data);

// your code goes here

return 0;

}

Página 2

Información

Descripción
Computer Science Apunte sobre typedef, creado por Anirudh pandey el 10/04/2018.
Creado por
Anirudh pandey
Visitas
0
Etiquetas
typedef organization
Valoración

Escríbenos

¿Sobre qué es tu mensaje?

¿Qué te parece el nuevo diseño?

¿Te gusta?