Summary @ usage in C,

Source: Internet
Author: User

Summary @ usage in C,

Usage in a string

1. Everyone on Earth knows that string constants in C # can start with @. This advantage is that escape sequences are not processed and output as they are, that is to say, we can easily coding without adding \ (reversed) to escape characters. For example,

[Csharp]View plaincopyprint?
  1. String filePath = @ "c: \ Docs \ Source \ a.txt" // rather than "c: \ Docs \ Source \ a.txt"

 

2. To include a double quotation mark in a string caused by @, two pairs of double quotation marks are required. At this time, you cannot use \ to escape the double quotation marks, because the escape purpose of \ here has been blocked. For example,

[Csharp]View plaincopyprint?
  1. @ "Ahoy! "" Cried the captain. "// output:" Ahoy! "Cried the captain.

It is a bit like the single quotation mark constant Processing Method in SQL:

[Csharp]View plaincopyprint?
  1. DECLARE @ msg varchar (100)
  2. SET @ msg = ''Ahoy! ''Cried the captain. '-- the output is: 'ahoy! 'Cried the captain.


3. @ Recognizes line breaks
In fact, I don't know how to describe this feature. I just accidentally discovered it. Let's take a look at the following code:

[Csharp]View plaincopyprint?
  1. String script = @"
  2. <Script type = "" type/javascript "">
  3. Function doSomething ()
  4. {
  5. }
  6. </Script> ";


Ease of thinking: Write js in the cs file, and the structure is very clear. Normally we are coding like this:

[Csharp]View plaincopyprint?
  1. String script2 =
  2. "<Script type = \" type/javascript \ "> function doSomething () {}</script> ";
  3. // Or
  4. String script3 =
  5. "<Script type = \" type/javascript \ ">" +
  6. "Function doSomething () {" +
  7. "} </Script> ";



We usually select the latter because the js Code is generally long, the method body is large, or other variables need to be connected, so that the structure is clearer.

Note: If the number of "splices" is large, you should consider using StringBuilder to improve performance.

It is also common to splice SQL statements in a program, such

[Csharp]View plaincopyprint?
  1. Private const string SQL _INS_USER = @"
  2. Insert into t_User ([UserName], [Password], Email)
  3. VALUES (@ UserName, @ Password, @ Email )";


 

[Csharp]View plaincopyprint?

Haha, this is like writing a stored procedure, maintaining a high degree of code clarity.HoweverYou need to pay attention to the following test code:

[Csharp]View plaincopyprint?
  1. Private const string SQL _INS_USER1 = @"
  2. Insert into t_User ([UserName], [Password], Email)
  3. VALUES (@ UserName, @ Password, @ Email )";
  4. Private const string SQL _INS_USER2 = @ "INSERT INTO t_User ([UserName], [Password], Email)
  5. VALUES (@ UserName, @ Password, @ Email )";
  6. Private const string SQL _INS_USER3 = @ "INSERT INTO t_User ([UserName], [Password], Email) VALUES (@ UserName, @ Password, @ Email )";
  7. Static void Main (string [] args)
  8. {
  9. Console. WriteLine (SQL _INS_USER1.Length); // 126
  10. Console. WriteLine (SQL _INS_USER2.Length); // 112
  11. Console. WriteLine (SQL _INS_USER3.Length); // 86
  12. }


 


We can see that the lengths of the three strings are different, 14 = 126-112 and 26 = 112-86. Note that in the Code Editor, after the first line break symbol in SQL _INS_USER1, I indent 13 spaces (before INSERT), while
After the first line break in SQL _INS_USER2, I indented 25 spaces (before VALUES ),
Then, add a line break, just 14 and 26

My GOD!

Writing code in this way improves the clarity and simplicity of the code, but it creates another problem in the absence of lines: character length!
In many scenarios, the shorter the string, the better. For example, you can use ADO. NET to send SQL statements to the database for execution.
So use it with caution!


Usage in binary identifiers
In the C # specification, @ can be the first character of the identifier (Class Name, variable name, method name, etc.) to allow the reserved keyword in C # as its own defined identifier.
For example

[Csharp]View plaincopyprint?
  1. Class @ class
  2. {
  3. Public static void @ static (bool @ bool ){
  4. If (@ bool)
  5. System. Console. WriteLine ("true ");
  6. Else
  7. System. Console. WriteLine ("false ");
  8. }
  9. }
  10. Class Class1
  11. {
  12. Static void M (){
  13. Cl \ u0061ss. st \ u0061tic (true );
  14. }
  15. }



Note: Although @ appears in the identifier, it is not part of the identifier.
Therefore, the preceding example defines a class and contains a method named static and a parameter named bool.

This facilitates cross-language transplantation. Because a word is reserved as a keyword in C #, but it may not be in other languages.


Summary of C language training

After one semester of C language learning, we started the C language training phase and tried to write a complicated program system by ourselves. During the two-week period, our colleagues in the same group felt that the C language training and the programs we encountered in the normal class were very different, the challenges that have been tested and overcome are incomparable. Fortunately, the partners in the same group have cooperated with each other, with a clear division of labor and joint solutions to problems. They have overcome the complicated procedures of C language training. Here, I feel a lot as a participant.

When I first came into contact with C, I had learned some VB-related content, which is a little helpful in algorithm and thinking. Looking back at the course of this semester, the most basic is the data format of C. Let us know how to use integers, floating-point numbers, and character constants in C. Then, after learning about data conversion and skilled data processing, I began to learn about data structures, such as arrays and structs, some things are very simple from the perspective of existing knowledge, and there are still some complicated concepts such as pointers. However, learning this is far from enough. in C language, there is still a lot of more classic, important, and practical knowledge.

Let's talk about functions. Although many programming languages have functions, I think C functions are the most attractive. The method for learning a function is relatively simple. There are only two words to remember: Remember the function, the purpose of the function, and how to input and output the function. In essence, a function is a common program. Using it can help us save a lot of programming time and learn the "high person" of C language, before writing a program, a smart programmer always finds out how many programs he has written can be replaced by functions. For example, you can use the strcmp () function in C language as long as one sentence. If you write your own code, it is difficult to implement 30 sentences. You can imagine that the function is practical and fast. In our C Language Training code, functions are fully applied. It can be said that the complex code of the Training Questions is accumulated by calling and nesting countless functions.

It should be noted that some of them were motivated by some large programs at the beginning, so they saw tedious data conversion and simple algorithms at the beginning, I am bored and want to develop a few satisfactory programs by myself. Although this idea is very good, we say that there is no foundation, and it is simply to move some out-of-the-box design methods, is optional. You must know that the program design focuses on personal thinking. If you are bound by some ready-made ideas at the beginning, you will feel boring in the future.
We know that pointers are actually the soul of the C language. Many data structures can be said to be proficient before we learn them. So our task is to let the data structure run in the pointer. Of course, it is a very painful thing to get started with these new things. Therefore, we must look at the pointer with a very visual mind, so it cannot be too solid. Therefore, new things, such as the representation of struct in pointers, and the use of arrays and multidimensional arrays in struct are all added, at the same time, we fully understand the data representation of the original C data organization. When we have completed these three steps, we can proudly say that we have a solid foundation and can further learn about algorithms, design concepts, and other deep-seated things.
However, pointers and struct, which are too abstract, are a bit "understandable" when learning C language. However, in the current C language training, such an important C language knowledge, be sure to be proficient and practical. In the large program of practical training, the expressions of struct in pointers, arrays, and the application of struct are all reflected, without pointers, our work cannot be expanded. Therefore, during the practical training period, on the basis of consolidating basic knowledge, we overcame practical training topics one by one, overcome difficulties, and improve our self-confidence.

Finally, let's talk about the program software in our group. The store product management system is a program that facilitates application, solves practical problems, and facilitates actual management. The design code is complex and the structure is rigorous. In about one week of programming, the team members encountered the above difficulties, including the lack of programming ideas, and even some knowledge points such as pointers, problems arising during the work. However, when we work together to solve these difficulties, we can find ourselves... the remaining full text>

C language knowledge Summary

C language Overview
Chapter 1. Overview
1. Basic knowledge of C Language
1.1 C language execution steps
Edit-enter the program code to generate the source program *. c
Compile-syntax analysis error: translation to generate the Target Program *. obj
(Syntax or logic error, starting from the first change, variable definition, statement format, expression format, etc)
Link-assemble with other target programs or libraries to generate executable programs *. exe
Run
1.2 Basic knowledge of the main Function
Location of the main () function
C Programs are always executed from the main () function.
A c program can contain a main function, that is, the main () function. It can also contain a main () function and several other functions.
1.3. c program structure
Functions and main functions
A program consists of one or more functions.
There must be one and only one main function main ()
Program Execution starts from main and ends in main. Other functions can be executed through nested calls.
Program Statement
A c program consists of statements.
Use ";" as the statement Terminator
Note
//
Or
/**/Is a comment and cannot be nested
No compilation code
1.4 c program writing rules
Used to Use lowercase letters, case sensitive
No row number. No program line concept: A statement usually occupies one row.
Empty rows and spaces can be used.
It is commonly used for the writing format of the tooth form; statements of the same hierarchy are aligned up and down.
Chapter 2 Basic Data Types and operations
2.1. Data Type of c program
Note the differences between types and variables (the types are fixed names and variables are their own names)
Storage space occupied by Variables
Data Type
Basic types: integer, complex, and floating point (single precision and Double Precision)
Construction type: array type and struct type
Pointer type
Null type
Note the initial value Assignment Method for the basic type.
Basic Data Type Representation
Integer Data
Decimal: starts with a non-zero number, for example, 123,-9, 0
Octal; starts with 0, for example, 0123,067
Hexadecimal: starting with 0x, for example, 0x123, 0xff
Real Data
Decimal: it must contain a decimal point, for example, 123.0,-9.0.
Exponential form, for example, 1.23E3, 0.9e-2, 5e2
Balanced data
Common characters: for example, 'A', '2', 'h ','#'
Escape characters: for example, '\ n',' \ 100', '\ xlf ,'\\'
(Realize the alignment of several columns: Specify the width. For example, % 100 \ '\ t)
(String Length. "Abc \ n \ t \" strlen 6; sizeof 7)
Storage length of the basic data type
Integer
Int Byte Count 2-digit 16-32768-32767
Short 2 16-32768-32767
Long 4 32-2147483648-2147483647
Real-type
Float 4 32 3.4e-38---3. 4e38
Double 8 64 1.7e-308---1. 7e308
Character Type
Char 1 8-128----127
2.2 identifier naming rules
C-language flag naming rules
An identifier consists of numbers, letters, and underscores.
The identifier must start with a letter or underline.
The identifier cannot be a reserved word (keyword) in C language)
For example, auto extern sizeof float static case for struct char goto switch continue in typedef const if union default long ...... remaining full text>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.