Indispensable Windows Native (3), windowsnative

Source: Internet
Author: User
Tags switch case

Indispensable Windows Native (3), windowsnative

[Download source code]


Indispensable Windows Native (3)-C language: operators, expressions, conditional statements, cyclic statements, steering statements, empty statements, etc.



Author: webabcd


Introduction
Indispensable C language for Windows Native

  • Operator
  • Expression
  • Condition Statement
  • Loop statement
  • Turning statement
  • Empty statement



Example
1. Operators
COperator. h

#ifndef _MYHEAD_OPERATOR_#define _MYHEAD_OPERATOR_ #ifdef __cplusplus  extern "C"#endif  char *demo_cOperator();#endif  

COperator. c

/** Operator */# include "pch. h "# include" cOperator. h "# include" cHelper. h "char * demo_cOperator () {// Arithmetic Operator: +,-, *,/, %, ++, -- // relational OPERATOR: >,<,=,> =, <= ,! = // Logical operator: &, | ,! // Bitwise OPERATOR: &, | ,~, ^, <,> // &-The bitwise AND: are both 1 and 1, and 0 in other cases. For example, 1001 & 0001 = 0001 // |-by-bit or: if one is 1, the value is 1. Otherwise, the value is 0. For example, if 1001 | 0001 = 1001 // ^-bitwise OR: if the difference is 1, the value is 0; for example, 1001 | 0001 = 1000 //~ -Non-bitwise :~ 1001 = 0110 // value assignment operator: =, + =,-=, * =,/=, % =, & =, |=, ^ =, >>=, <<=// condition OPERATOR: What is the three-object operator?: // Pointer OPERATOR: * used to get content & used to get the address // I ++, I itself plus 1, the value of the expression I ++ is the value before I is added 1 // ++ I, And I itself is added 1, the expression ++ I value is the int I = 0; I ++; // here the I value is 1, the value of I ++ is 0 int j = 0; ++ j; // here, the value of j is 1, the value of ++ j is 1 // sizeof-is the keyword in C, not a function, calculate the space occupied by a data type. int intSize = sizeof (short); // 2, the occupied space of int short long on different platforms may be different. You can use sizeof to know the occupied space of char * str = "abcdefghijklmnopqrstuvwxyz"; int dataSize = sizeof (str ); // 4. Here, the space occupied by the str pointer is calculated. return str_concat2 (int_toString (intSize), int_toString (dataSize ));}


2. expressions, condition statements, cyclic statements, turning statements, and empty statements
CStatement. h

#ifndef _MYHEAD_STATEMENT_#define _MYHEAD_STATEMENT_ #ifdef __cplusplus  extern "C"#endif  char *demo_cStatement();#endif  

CStatement. c

/** Expressions, condition statements, loop statements, steering statements, empty statements, etc. */# include "pch. h "# include" cStatement. h "# include" cHelper. h "char * demo_cStatement () {// the so-called expression statement is composed of the expression plus the Semicolon"; "// I ++, I itself plus 1, the value of the expression I ++ is the value before I is added 1 // ++ I, And I itself is added 1, the expression ++ I value is the value after I plus 1 // composite Statement (enclosed in braces) {int p1 = 1; int p2 = 2;} // only "; "is called the empty statement while (0) {; // This is the empty statement} // The above is equal to the following while (0 ); // The preceding statement is equal to the following while (0); // the Statement of the branch structure (if else) int a = 0, B; if (a = 1) B = 1; // Note: Variables If a is not initialized before, it cannot be compiled here. That is to say, if (a = 1) B = 2 cannot be used for unassigned variables; else if (a = 2) B = 3; else B = 4; // switch case statement (switch case) int x = 0, y; switch (x) {case 1: y = 2; break; case 2: y = 3; break; default: y = 4;} // statement of the branch structure (? :) Int m, n = 0; m = n = 1? 2: 3; // loop Statement (while) int I = 0; while (I <100) {I ++;} // loop Statement (do while) int j = 0; do {j ++;} while (j <100); // loop statement (for) for (I = 0; I <100; I ++) {} for (I = 0; I <100;) {I ++;} for (I = 0, j = 0; I <100 & j <100; I ++, j ++) {I ++; j ++;} int z = 0; for (; z <100;) {z ++ ;} // turning statement: break-Skip loop // turning statement: continue-Skip the remaining statement of the loop body and directly go to the next loop judgment // turning statement: return-exit function, and provides the return value // steering statement: goto-jump to the specified identifier and execute the subsequent statement (for example, when a multi-layer nested statement exits, it is reasonable to use goto) int result = 0; myAnchor: // custom identifier (the identifier is added with a colon) if (result = 1) {result = 100 ;} if (result = 0) {result = 1; goto myAnchor; // jump to the specified identifier (myAnchor :), and execute the following statement} return str_concat2 ("Check the code and comment", int_toString (result ));}



OK
[Download source code]

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.