In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of "C language novice case analysis". The editor shows you the operation process through the actual case, and the operation method is simple, fast and practical. I hope this article "C language novice case analysis" can help you solve the problem.
1. Constant
As the name implies, constants are values that do not change. Constants in C language are divided into the following categories:
Literal constant
Constant variables modified by const
# identifier constants defined by define
Enumeration constant
Code description:
# include// literal constant int main () {30; 3.14; 'Wendichelp / character "abcdf"; return 0; int main () {const int a = 10; a = 20; printf ("% d\ n", a); return 0;}
You can see that the original variable an is not allowed to be modified with const modification, and at this time an is a constant variable, because in C language, const modified an is essentially a variable, but it cannot be modified directly. It has constant attributes.
/ / define-defined identifier constant # define MAX 100int main () {printf ("% d\ n", MAX); int a = MAX; printf ("% d\ n", a); return 0;}
/ / enumerate constant enum color {/ / enumerate constant RED, BLUR, ORANGE}; int main () {enum color c = RED; return 0;} II. String
A string is a string of characters enclosed by double quotation marks. It should be noted that the end mark of the string is\ 0, which is not counted as the contents of the string when calculating the length of the string.
Code interpretation:
Int main () {/ / char character type / / char ch = 'asides'; / / single quotation marks are characters / / C language has no string type / / char chh = "asdfgg"; / / A double quotation mark is a string / / you can also use an array to store char arr1 [] = "abcdefg" / / finally, there is a\ 0 char arr2 [] = {'a 'axiomagematic'] = {'axiaxiangyangyuanzhongyuanzhongyuzhuo'}; / / you can stop stopping randomly only if you encounter\ 0, because you don't know which one is\ 0 printf ("% s\ n", arr1); printf ("% s\ n", arr2); return 0;}
Escape characters
Simply put, it is a character that changes its meaning.
Use a simple example to illustrate:
It is equivalent to adding a symbol to change the original meaning, is it possible to add a character transformation to any character? In fact, it is not. The following are common escape characters:
You can simply try the above escape characters, which are very common on the way to programming in the future. here is an article to explain the use of the above code separately. Just have a simple understanding of it now. Let's experiment.
IV. Notes
Comments, uh, this is very simple. In the code, the unwanted code can be deleted directly or commented out. And if some code in the code is difficult to understand, you can write a comment text to explain it. In order to be a good programmer, it is necessary to write comments.
Generally use / / to comment, is the style of C++, can be one-line and multi-line comments, while the C language is / * / style, each has its own characteristics
I hope you can keep the advantage of writing notes.
5. Select sentence
There are choices everywhere in life, and these choices will affect your future direction. For example, if you study hard and knock on the code every day, you will be called a good programmer. If you don't study hard and knock on the code, you can't become a programmer. This is the choice.
C language has if else and Switch statements. Here is a brief understanding of if statements with code. Switch statements will be explained in detail in subsequent articles.
Int main () {int n = 0; printf ("do you want to study hard? (1ap0); scanf ("% d", & n); if (n = 1) {printf ("good programmer\ n");} else {printf ("can't be a programmer\ n");} return 0;} sixth, loop statement
Some things are done repeatedly, for example, some people go to work day after day, study day after day, and repeat to do one thing is the cycle, but this will also be accompanied by sudden events to break these repetitive things. for example, if you win 5 million in the lottery, you don't have to go to work day after day and so on.
How to achieve this cycle in C language?
While statement (explanation)
For statement (described in later articles)
Do while statement (described in later articles)
Since it is a new acquaintance, we will have a brief understanding of it. We will explain it later in detail. I hope you will understand it. Here is a simple understanding of the while loop with code:
Int main () {int line = 0; printf ("write good code\ n"); while (line
< 20000) //让这个循环终止的条件 { printf("写代码:%d\n", line); line++; } if (line >= 20000) {printf ("I have become Daniel\ n");} else {printf ("I will continue to work hard to become Daniel\ n");} return 0;} 7, function
We believe that functions are not unfamiliar in mathematics. Different x can get different results, different x can get different results, and functions in C language are similar to those in mathematics, but the expression is different. The characteristic of functions in C language is that they simplify the code and can be used repeatedly, without having to write the same code repeatedly. Let's use the code to give you a brief understanding of the function:
# includeint main () {/ / the addition of two arbitrary numbers: int a = 0; int b = 0; int sum = 0; printf ("enter two operands: >"); scanf ("% d% d", & a, & b); sum = a + b; printf ("sum =% d\ n", sum); return 0 } the above code is written as follows: int Add (int x, int y) / / return type int, function name add, function parameters in parentheses, {} internal function body {return x argument;} int main () {int a = 0; int b = 0; int sum = 0; printf ("enter two operands: >"); scanf ("% d% d", & a, & b) Sum = Add (a, b); printf ("sum =% d\ n", sum); return 0;} VIII, array
If you want to store 1-10, how do you store it? If it is still too troublesome to define one by one, the C language gives the definition of an array, a collection of elements of the same type, in an array, if you want to access a number, you need to know the subscript. Each element of the array has a subscript, and the subscript starts with 0, which is explained by the following code:
The use of arrays:
This is the end of the introduction of "case Analysis of beginners to C language". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.