• Computers
  • Computer Programming
  • C Programming
  • The Difference Between

What is the difference between enumrerated datatype and typedef?

User Avatar

Wiki User

βˆ™ 2005-09-29 12:49:49

Best Answer

Its very Simple that using Enumerated data type you are making special integers that flow within range, While a typedef is redefining data type with new name. Example: like defining enum Days{sun,mon,tue.....} makes an integer definition that can have 0-7 values So if u do following: Days x=sun; or Days x=0; then x=x+2; is 2 or tue and x=x+7; is 0 or sun again... Means its modulo 7 data type ................. While doing this: typedef Days WeekDays; renames Days as WeekDays Similary typedef int NUMBER; renames int as NUMBER .But wait it is one more name for the data type.. So simply enum creates a numeral modular datatype with a range while typedef creates another name for it. Rupesh K Joshi

2005-09-29 12:49:49
This answer is:
User Avatar

Your Answer


Related Questions

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.

C program to swap two numbers using pointers as function aruguments?

Voila: typedef float DataType; void swap(DataType* const a, DataType* const b) { DataType c = *a; *a = *b; *b = c; }

What is the difference between Typedef and Reference in C plus plus?

A typedef is a compiler macro. A reference is a pointer, usually implemented with transparent syntax. They have no relationship between each other.

What is difference between define and typedef in c plus plus?

#define is a preprocessor directive used to declare macros. typedef is a C++ keyword to define a data type.

Difference between define and typedef?

typedef keep the property of attributes whereas #define won't for example #define char* m_type typedef char* p_type m_type a, b; p_type c,d In above case a, c and d are pointer types , where as b in char type only. Which is not our intention. In another example which shows #define keeps string attributes whereas typedef won't. #define int INT; typedef int MYINT unsigned MYINT a; unsigned INT a; The above example won't work as it won't change to unsigned int a. And in #define case it will simply works!!!.

What is typedef in c programming language?

A typedef is a type definition.

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;

How do you declare data types?

typedef data_type data_name, for instance:typedef int myDataType;

What is the function of typedef statement?

typedef is used to create user defined data types

What is the difference between Typecast and Typedef?

Typecasting is to make a variable of one type, act like another type for one single operation. Type-def is to assign alternative names to existing types.

What is a typedef in C programming?

A typedef is a type definition. That is, we are defining a new type. In some cases, a typedef is merely an alias for an existing type. We typically use aliases as a shorthand for complex types: typedef unsigned long ULONG; Here, we can use the alias ULONG in place of unsigned long. We can also use typedef to define user-defined types, such as structures and unions: typedef struct person { char* first_name; char* last_name; int age; };

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.

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.

What is difference between c plus plus struct and c struct?

The internal members of a struct are the same for both C and C++. However, a C struct has no member methods and is entirely public. A C++ struct, on the other hand, is public by default but otherwise works exactly the same as a class.Aside from object-oriented nature of the C++ struct, the major difference between the two is in the declaration.In C, you could declare a struct in a variety of ways:struct foo {...}; struct foo bar;struct foo {...} bar;typedef struct foo {...} bar;The above three lines are all functionally equivalent (although you can't use all three in the same namespace, of course). However, the explicit use of typedef is the preferred method in C, thus allowing new instances of the structure to be created without the need to continually use the struct keyword:typedef struct foo {...} bar;foo another_bar;foo yet_another_bar;In C++ the use of typedef is not necessary, so the declarations can use the more simplified form:struct foo {...} bar;foo another_bar;foo yet_another_bar;Note that typedef is not implied, it's simply not required. You can still use a typedef if you want, but it's existence is mostly for backward compatibility with C. In fact, the only time a typedef is ever required is when the tag name or instance name clash with a function name in the same namespace. Although its ultimately better to avoid name clashes altogether, a typedef will resolve the clash.

How typedef feature used with structure?

Example: typedef struct MYTYPE { ... ...fields... ... ... struct MYTYPE *self_pointer_if_needed; ... } MYTYPE; MYTYPE myvar, *myptr;

What is storage claases in c language?

They is static, auto, extern and typedef. (Well, typedef aint't an actual storage class, it means 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.

What is typedef in C?

AnswerA typedef declaration lets you define your own identifiers that can be used in place of type specifiers such as int, float, and double. A typedef declaration does not reserve storage. The names you define using typedef are not new data types, but synonyms for the data types or combinations of data types they represent. The name space for a typedef name is the same as other identifiers. The exception to this rule is if the typedef name specifies a variably modified type. In this case, it has block scope.When an object is defined using a typedef identifier, the properties of the defined object are exactly the same as if the object were defined by explicitly listing the data type associated with the identifier.Examples of typedef DeclarationsThe following statements declare LENGTH as a synonym for int and then use this typedef to declare length, width, and height as integer variables:typedef int LENGTH;LENGTH length, width, height;The following declarations are equivalent to the above declaration:int length, width, height;Similarly, typedef can be used to define a class type (structure, union, or C++ class). For example:typedef struct { int scruples;int drams;int grains;} WEIGHT;The structure WEIGHT can then be used in the following declarations:WEIGHT chicken, cow, horse, whale;In the following example, the type of yds is "pointer to function with no parameter specified, returning int".typedef int SCROLL();extern SCROLL *yds;In the following typedefs, the token struct is part of the type name: the type of ex1 is struct a; the type of ex2 is struct b.typedef struct a { char x; } ex1, *ptr1;typedef struct b { char x; } ex2, *ptr2;Type ex1 is compatible with the type struct a and the type of the object pointed to by ptr1. Type ex1 is not compatible with char, ex2, or struct b.C++ The remainder of this section pertains to C++ only.In C++, a typedef name must be different from any class type name declared within the same scope. If the typedef name is the same as a class type name, it can only be so if that typedef is a synonym of the class name. This condition is not the same as in C. The following can be found in standard C headers:typedef class C { /* data and behavior */ } C;A C++ class defined in a typedef without being named is given a dummy name and the typedef name for linkage. Such a class cannot have constructors or destructors. For example:typedef class { Trees(); } Trees;Here the function Trees() is an ordinary member function of a class whose type name is unspecified. In the above example, Trees is an alias for the unnamed class, not the class type name itself, so Trees() cannot be a constructor for that class.External Links:You can find more questions with answers for C typedef from http:/

What is the difference between structure and structure using typedef with example?

Consider the following structure:struct data_t { /* ... */ };The name of this type is struct data_t. This means that we must include the struct keyword whenever we declare any instances of the type or declare a pointer to the type:struct data_t object;struct data_t* ptr;To remove the verbosity of the otherwise redundant structkeyword, we can use an alias:typedef struct data_t data;data object;data* ptr;To simplify things further, we can combine the alias with the structure's definition:typedef struct data_t { /* ... */ } data;Note that the _t suffix is conventionally used to denote a user-defined type as opposed to an alias. However, its usage is not consistent. For instance, the wchar_t type is not a type, it is implemented as an alias in the C standard library header:typedef unsigned short wchar_t;In C++, the typedef keyword is not required; it is retained purely for backward compatibility with C. Aliases are introduced with the using keyword, never with typedef. We only use typedef when we are explicitly writing code intended for compilation under both C and C++.Note also that wchar_t (amongst others) is a built-in type in C++, so we don't need to include the C standard library to make use of it, unless we are writing code for C.

What is difference between define and typedef in c?

defines are handled by a preprocessor (a program run before the actual c compiler) which works like replace all in you editor. Typedef is handled by the c compiler itself, and is an actual definition of a new type. The distinction given between #define and typedef has one significant error: typedef does not in fact create a new type. According to Kernighan & Richie, the authors of the authoritative and universally acclaimed book, "The C Programming Language": It must be emphasized that a typedef declaration does not create a new type in any sense; it merely adds a new name for some existing type. Nor are there any new semantics: variables declared this way have exactly the same properties as variables whose declarations are spelled out explicitly. In effect, typedef is like #define, except that since it is interpreted by the compiler, it can cope with textual substitutions that are beyond the capabilities of the preprocessor. There are some more subtleties though. The type defined with a typedef is exactly like its counterpart as far as its type declaring power is concerned BUT it cannot be modified like its counterpart. For example, let's say you define a synonim for the int type with: typedef int MYINT Now you can declare an int variable either with int a; or MYINT a; But you cannot declare an unsigned int (using the unsigned modifier) with unsigned MYINT a; although unsigned int a; would be perfectly acceptable. typedefs can correctly encode pointer types.where as #DEFINES are just replacements done by the preprocessor. For example, # typedef char *String_t; # #define String_d char * # String_t s1, s2; String_d s3, s4; s1, s2, and s3 are all declared as char *, but s4 is declared as a char, which is probably not the intention. typedef also allows to delcare arrays, # typedef char char_arr[]; # char_arr my_arr = "Hello World!\n"; This is equal to # char my_arr[] = "Hello World!\n"; This may lead to obfuscated code when used too much, but when used correctly it is extremely useful to make code more compat and easier to read.

What is the use of typedef?

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

Is address a user-defined data type?

You can define a data-type called 'address': 1. typedef void *address; 2. typedef struct address { char country [32]; char state [32]; ... } address.

What is the the purpose of typedef feature. How this feature is used in conjunction with structures. Explain?

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++.}