O GoConqr está de visual novo! Conte para nós o que você achou.

Notas

typedef

Anirudh pandey Computer Science Inglês 2 páginas

Conteúdo das notas (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

Informações

Descrição
Computer Science Notas sobre typedef, criado por Anirudh pandey em 10-04-2018.
Criado por
Anirudh pandey · abr 2018
Atualizado
10 abr 2018
Visualizações
0
Tags
typedef organization
Avaliação

Fale Conosco

Sobre o que é sua mensagem?

O que você acha do novo visual?

Você gostou?