In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the knowledge of "C language selection, loop, function, array and operator instance analysis". Many people will encounter this dilemma in the operation of actual cases. next, let the editor lead you to learn how to deal with these situations! I hope you can read it carefully and be able to achieve something!
1. Select statement
If you study hard, get a good offer and get to the top of your life. If you don't study, graduation is equal to unemployment, go home and sell sweet potatoes. That's the choice!
# includeint main () {int a = 0; printf ("1: study hard, take the big factory offer 2, the dormitory is rotten, and lose your job upon graduation\ n\ n"); printf ("Please choose 1 or 0:->"); scanf ("% d", & a); if (a = = 1) {printf ("come on, like you! Else {printf ("go home and sell sweet potatoes! \ n ");} return 0;}
2. Circular statement
There are three kinds of loops in C language, which are for loop, while loop and do while loop, which I will demonstrate with examples below.
For cycle
# includeint main () {int I = 0; for (I = 0; I
< 10; i++) { printf("%d ", i); } return 0;} while循环 #includeint main(){ int i = 0; while (i < 10) { printf("%d ", i); i++; } return 0;} do while循环 #includeint main(){ int i = 0; do { printf("%d ", i); i++; } while (i < 10); return 0;} 其中 i 为循环变量,i++ 为循环变量增值,i>= =
< b ? a : b; //条件操作符,如果 a>B condition is true, assign a to max, otherwise b is assigned to max printf ("max =% d\ n", max); return 0;}
9. Comma expression
Exp1, exp2, exp3,... ExpN
# includemain () {int x, y, z; x = y = 1; / / comma expression that performs each operation from left to right, but only takes the result of the last comma z = (x, y, y, + + y) / / execute the first two commas first, x = 2, x = 2, y = 2, y = 2, and then the last comma, z = ny, preceded + +, so z=y=3 printf ("x =% d\ ny =% d\ nz =% d\ n", x, y, z); return 0;}
It is important to note here that the assignment operator takes precedence over the comma expression, that is, if there are no parentheses after z, the compiler will first assign the value of x to z and then execute the subsequent comma expression.
# includemain () {int x, y, z; x = y = 1; / / comma expression, performing each operation from left to right, but only taking the result of the last comma / / assignment operator takes precedence over the comma expression, assign x to z first, then z = 1 / / execute the first two commas, x = 2, y = 2, y = 2, y = 3 z = x, y, y, printf ("x =% d\ ny =% d\ nz =% d\ n", x, y, z); return 0;}
10. Subscript references, function calls, and structure members
[] (). ->
# includestruct Stu {/ / define a structure type char name [15]; int age; char sex [6];}; int main () {struct Stu s = {"Zhang San", 20, "male"}; / / define a structure variable s with the structure type and initialize printf ("% s\ t% d\ t% s\ n", s.name, s.age, s.sex) / / use. Operator to access return 0;} to structure members
This is the end of "C language selection, Loop, function, Array and operator instance Analysis". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.