Keyword typedef in C
The C program language provides a typedef keyword, which you can use to provide the type for a new name. Here is an example to define a BYTE entry for 1-byte numbers (like unsigned char).
typedef unsigned char BYTE ;
After defining this type, the BYTE identifier can be used as an abbreviation for unsigned char types, for example:
BYTE b1 , b2 ;
By convention, uppercase letters are used for these definitions to make it easier for users to remember, but you can use lower case letters as follows:
typedef unsigned char byte ;
You can also use typedef to provide a name for the user defined data type. For example, you can use typedef with a structure to define a new data type and then use that data type to define structure variables directly as follows:
#include #include typedef struct Books { char tieude [ 50 ]; char tacgia [ 50 ]; char chude [ 100 ]; int id ; } Book ; int main ( ) { Book book ; strcpy ( book . tieude , "Lap trinh C" ); strcpy ( book . tacgia , "Pham Van At" ); strcpy ( book . chude , "Ngon ngu lap trinh C" ); book . id = 1234567 ; printf ( "Tieu de: %sn" , book . tieude ); printf ( "Tac gia: %sn" , book . tacgia ); printf ( "Chu de: %sn" , book . chude ); printf ( "ID: %dn" , book . id ); printf ( "n===========================n" ); printf ( "QTM chuc cac ban hoc tot! n" ); return 0 ; }
Compiling and running the above C program will result:
typedef vs #define in C
#define is a directive in C which is also used to define aliases (abbreviations) for diverse data types similar to typedef but there are the following differences:
The typedef is limited to providing abbreviations for types only, while #define can be used to define nicknames for both values, as you can define 1 as ONE, .
The typedef translation is performed by the compiler, while the #define command is processed by the preprocessor.
Here is the simplest use of #define :
#include #define TRUE 1 #define FALSE 0 int main ( ) { printf ( "Gia tri TRUE tuong duong: %dn" , TRUE ); printf ( "Gia tri FALSE tuong duong: %dn" , FALSE ); printf ( "n===========================n" ); printf ( "QTM chuc cac ban hoc tot! n" ); return 0 ; }
Compiling and running the above C program will result:
According to Tutorialspoint
Previous lesson: Bit field in C
Next lesson: Input & Output in C
You should read it
- 12 free keyword analysis tools replace Google Keyword Tool
- How to use Google Keyword Planner
- 12 best keyword analysis tools
- Google Keyword tool
- How to do keyword research for SEO
- 6 most effective keyword research (Keyword Research)
- How to do and research on Long Tail Keyword in SEO - Part 1
- Namespace in C #
May be interested
- 5 common mistakes when researching keywords for SEOavoiding these errors can save you time, rethink your marketing strategy and bring the right audience to your website.
- Facebook tests the status search feature by keywordwith this feature you can quickly find the phone number or restaurant name that friends posted a few months ago on facebook with a simple search keyword.
- What is Search volume? Why care about search volume?search volume (keyword search volume) refers to the number of searches for a certain keyword within a selected time frame (usually 1 month). in most keyword research tools, the number of searches is an average value based on the past 12 months.
- DISTINCT keyword in SQLthe distinct keyword in sql is used in conjunction with the select statement to remove all duplicate records and retrieve only records.
- 47 steps to increase keyword rankings and website traffic effectively and sustainably over timethe problem most people have is not about how they can set up a website or even start a blog, it's about how they can actually drive traffic to their website.
- Basic C # syntaxc # is an object-oriented programming language. in an object-oriented programming method, a program of diverse objects that interacts with the ways of action. actions that an object can receive are called methods.
- 8 ways to do SEO to increase website trafficwith seo people, when the number of visitors to the website is increasing, it will have a big impact on whether it can sustain the keyword ranking in search results. therefore, how to increase website traffic is essential.
- Data type in C / C ++data type in c / c ++ while working with any programming language, you need to use various types of variables to store information. variables, nothing but memory locations are reserved for saving values. that is, when you create a variable, you reserved some space in memory for that variable.
- Apple and Google block apps with the keyword 'Flappy'according to techcrunch, both apple and google are making quiet moves to prevent applications that are about to be put on their app market that tend to follow the famous flappy bird game.
- Using Keyword Redirect opens the website via keywordskeyword redirect helps users to quickly open web pages via the shortcut settings for that website.