Uses typedef to name the struct as data

Utilizing Typedef With Structures

Declares a struct that stores the name and age of a person.

Afflluence Writng Service

It enables us to introduce equivalent words for information sorts which could have been declared some other way.

It is utilized to give New name to the Structure.

New name is utilized for Creating instances, Passing esteems to function,declaration etc…

Live Example : Sample Program

#include

int primary()

{

typedef int Number;

Number num1 = 40,num2 = 20;

Number answer;

answer = num1 + num2;

printf(“Answer : %d”,answer);

return(0);

}

Yield :

Answer : 60

Clarification of Program :

In the above program we have utilized typedef to create false name to information sort. We have created false name to ‘int’ information sort. We have given new name to whole number information sort i.e ‘Number’.

Linguistic structure to Use Typedef With Structures :

typedef int XYZ;

XYZ age;

XYZ roll;

Distinctive Ways of Declaring Structure utilizing Typedef :

typedef struct

{

char ename[30];

int ssn;

int deptno;

}employee;

Or, on the other hand

typedef struct Record

{

char ename[30];

int ssn;

int deptno;

}employee;

In the second case, Record is tag-name. ‘representative’ is only New Data Type. We can now create the factors of sort ‘worker’ Tag name is discretionary.

Declaring Variable :

worker e1,e2;

Live Example : Using Typedef For Declaring Structure

#include

typedef struct b1 {

char bname[30];

int ssn;

int pages;

}book;

book b1 = {“Let Us C”,1000,90};

int principle()

{

printf(“\nName of Book : %s”,b1.bname);

printf(“\nSSN of Book : %d”,b1.ssn);

printf(“\nPages in Book : %d”,b1.pages);

return(0);

}

Yield :

Name of Book : Let Us C

SSN of Book : 1000

Pages in Book : 90

Isso nos permite introduzir palavras equivalentes para tipos de informações que poderiam ter sido declaradas de outra maneira.

É utilizado para dar novo nome à Estrutura.

Novo nome é utilizado para Criação de instâncias, Passando estima a função, declaração etc …

Exemplo ao vivo: Programa de exemplo

#include

int primary ()

{

typedef int Number;

Número num1 = 40, num2 = 20;

Resposta numérica;

resposta = num1 + num2;

printf (“Resposta:% d”, resposta);

retorno (0);

}

Produção :

Resposta: 60

Esclarecimento do Programa:

No programa acima, utilizamos typedef para criar um nome falso para a classificação de informações. Criamos o nome falso para o tipo de informação ‘int’. Nós damos um novo nome para a classificação de informações de números inteiros, ou seja, ‘Número’.

Estrutura linguística para utilizar Type def com estruturas:

type def int XYZ;

Idade XYZ;

Rolo XYZ;

Formas Distintivas de Declaração de Estrutura utilizando Type def:

type def struct

{

char ename [30];

int ssn;

int deptno;

}empregado;

Ou, por outro lado

type def struct Record

{

char ename [30];

int ssn;

int deptno;

}empregado;

No segundo caso, Record é tag-name. ‘representante’ é apenas o Novo Tipo de Dados. Agora podemos criar os fatores de classificação de “trabalhador” O nome da etiqueta é discricionário.

Declarando Variável:

trabalhador e1, e2;

Exemplo ao vivo: Usando Type-def para declarar estrutura

#include

struct b1 {

char bname [30];

int ssn;

páginas int;

}livro;

livro b1 = {“Let Us C”, 1000,90};

princípio int ()

{

printf (“\ nNúmero do livro:% s”, b1.bname);

printf (“\ nSSN do Livro:% d”, b1.ssn);

printf (“\ nPáginas no Livro:% d”, b1.pages);

retorno (0);

}

Produção :

Nome do livro: Let us C

SSN do Livro: 1000

Páginas no livro: 90

You may also like...

1 Response

  1. 2017

    […] Uses typedef to name the struct as data […]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: Content is protected !!