answersLogoWhite

0

What is the use of typedef?

User Avatar

Wiki User

13y ago

Best Answer

The purpose of typedef is to assign alternative names to existing types, most often those whose standard declaration is cumbersome, potentially confusing, or likely to vary from one implementation to another

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the use of typedef?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the use of type def in c?

A typedef is used to define a type. The clue is in the name: typedef = type definition.


Use of typedef?

You use typedef to give a different name to a current data type. Consider the following: typedef int integer; Now everytime you do "integer x", it'll be an int. Basically, there is no case where you _must_ use it, only cases where it might be easier to have typedefs.


Typedef int a a a Is this possible in C?

No, but 'typedef int a;' is possible, it defines the type 'a'.


What are the Uses of typedef?

the purpose of typedef is to redefine the name of an existing variable type. e.g. typedef unsigned long int T; T v1,v2;


User defined data type in c plus plus?

Use "typedef" : both in C and C++.


How do we represent typedef in enterprise architect tool?

create class with typedef construct.and then add the base class with the name type


How is typedef different from int in c language?

They are entirely different things; int is a type, typedef is a way to define types.


Why should you use typedef in c language?

For no other reason than that it is required whenever you declare a type definition in C.


What is the main use for type def seems to be defining structures?

When you define a structure, C does not provide a type for that structure. In order to subsequently declare an instance of that structure, you need to use the word struct again. The typedef allows you to declare a type equivalent to the structure. For example... struct person { char* name, int phone}; struct person myperson; With typedef, you can simplify to... typedef struct person { char * name, int phone} person;person myperson; In C++, this is automatic, but not in C.


What is the difference between a macro and typedef?

A Macro is a preprocessor directive means that before compilation the macros are replaced. Where as typedef is defining a new data type which is same as the existing data type. Syntax: typedef Existing datatype New datatype For example typedef int NUMBER; Here NUMBER (New datatype)is defined as a data type which contains the properties same as int(Existing datatype). You can declare a variable of int as NUMBER a; is same as int a; similarly typedef int* NUMBERPOINTER; NUMBERPOINTER a; Here a is a pointer of integer type.


What is meant by the storage class of a variable?

auto, extern, static, register, typedef (only formally)


How typedef feature used with structure?

You use typedef to declare a synonym for an existing type. It's generally just a way of reducing a complex or cumbersome declaration outside your code to a more simplified, more easily understood declaration that you can use inside your code.Cumbersome example:void DoStuff( void (*)(int&, char& ), int&, char&); // Huh? Do what?Simplified example:typedef void (*pFunc) ( int&, char& );void DoStuff( pFunc, int&, char& ); // Aha! It's a function pointer!In relation to C structures, typedef provides a way to declare and name user-defined types, primarily so you don't have to use the struct keyword in the variable declaration. C++ structures are more flexible and the typedef keyword is optional.Structure examples for C:struct hard{ int i;double f;};// typedef is optional in C++, but required in C.typedef struct{int i;double f;} easy;int main(){struct hard hs; // Requires struct keywordeasy es; // Same as C++.}