Basic knowledge of C language ---- Union & enumeration & structure, basic knowledge ----
Struct tag (optional) {type 1 identifier 1; Type 2 Identifier 2; ......} (variable definition optional );
Tags available for union {type 1 identifier 1; Type 2 Identifier 2 ;........
} Optional variable definitions. The Union is similar to the struct, but there are key differences in the memory layout. Each member in the consortium is stored sequentially. in the consortium, all members are stored starting from the offset to zero (the positions are overlapping), and at a certain time point, only one member is actually stored in the address change.
Enumeration (it is used to declare a group of named constants. When a variable has several possible values, it can be defined as Enumeration type) enum optional label {content .....} optional variable definition. If a value is assigned to an identifier in the list, the identifier next to the identifier is greater than the value 1. however, for undefined identifiers, the names in enumeration cannot be displayed in the debugger and can be used in code debugging. # A constant defined by the define macro, it is replaced during compilation.
Sample program[Cpp]View plaincopyprint?
- # Include <stdio. h>
- Struct s
- {
- Int;
- Char c;
- } S1;
- Enum e
- {
- A, B = 3
- } E1;
- Union u
- {
- Int;
- Int B;
- Char c;
- } U1;
- Int main (void)
- {
- S1.a = 3;
- U1.a = 3;
- U1. B = 4;
- E1 = B;
- Printf ("struct: s1.a = % d \ n", s1.a );
- Printf ("enum: e1_ B = % d \ n", e1 );
- Printf ("union: u1.a. & = % x \ n", & u1.a );
- Printf ("union: u1. B. & = % x \ n", & u1. B );
- }
Running result
The running results show that all members in the Union share one storage address and only one storage address exists.
Basic knowledge of C Language
Yes. The landlord is very smart. Haha
C language entry question
For the C language, it is recommended that the author of Tsinghua's tan haoqiang be more suitable for beginners. Although the content of the book is not detailed enough, it is specific and easy to understand, however, the disadvantage is that the orchestration is not reasonable. If you choose to read this book, you are advised to read the while do ~ Before the while and for loops, read the function call chapter, which helps you better understand the program... this book is currently used for C language teaching in colleges and universities. It is based on 0 and has no difficulty in self-learning. Primer C is indeed a good book, but it is really not suitable for beginners. If it is all integrated, then you can say that it is a small achievement in C language, this book is suitable for people who have a certain degree of foundation. It is not recommended that you use this book to start learning.
For C ++, it must be determined that money can be written. This person's understanding of C ++ is unmatched by the vast majority of students who write teaching materials, his book is also the C ++ Teaching Book of the national key university. Although the content inside is a bit in-depth, the content in the book is indeed good, A lot of words are brilliant. For C ++ learning, especially for beginners, you must read the books written by this person. There are several editions of his books, preferably the new version. The old version does not matter and there will be no major changes. Like the C language, primer C ++ is also a very high usage book, which is not suitable for beginners and is not recommended for you to start learning.
Currently, software programming majors vary in the course classes of major colleges and universities across the country. Some schools learn C first and C ++ later. Some schools do not learn C, and direct C ++ has their own advantages and disadvantages, in my personal experience, it is recommended that you learn C first. After all, C is conducive to your learning of C ++, although some people say that C learning will help you learn C ++ with a lot of ideas fixed to the wrong position, learning programming is flexible, in addition, C is a very universal language and is suitable for writing large programs. On the basis of your C language, C ++ learning will be very smooth!
I hope you can learn this well and have your own achievements in the future. Also, you should never forget that programming is a hard job. If you have chosen this path, don't regret it. You should make great efforts in this kind of work diligently, otherwise, all your efforts will be in vain.