iOS Learning Day3

Source: Internet
Author: User

BOOL Data type

#define TRUE 1//#define Falae 0#define BOOL intbool flag=1;

BOOL type is essentially int type

C89 not provided

C99 has provided

You should give true or false when assigning values.

If a value of not 0 is given, it is stored as 1;

bool flag =tuue;
#include <stdio.h>
int main (int argc, const char * argv[])
{
BOOL Y=1;

{
printf ("%s", y? ")      True ":" Flase "); }//ternary operator

}

The flexibility of C language will bring about the hidden dangers of the program, and in some modern high-level languages it is not allowed to write 1 if(i=9) 2 { 3 } Msan Launch rockets!

logical Operators

&& logic: Maturity is true at the same time;

#include <stdio.h>
int main (int argc, const char * argv[])
{
if (i>=0&&i<=100)
{

}

}

Short-circuit is the so-called short-circuit phenomenon is the use of logical operators, when the previous logical operation results have been able to determine the entire operating conditions of the true and false to stop the operation, the latter is not the logic of the operation.
such as: a==0 && b==0 && c==0; When a==0 this expression is false, the b==0 && c==0 in the back will not be counted, because a==0 is false and can already determine the entire logic condition as false.
If you want to use a bitwise operator instead of a logical operator, the following:
A==0 & b==0 & c==0; This is actually a few bool type data bit and operation, equivalent to 1 & 1 & 1 (This is the case of all the logical expression is true), the result is also 1, when as the if condition, actually also with the above no difference.
Using the logical operator or bitwise operator as the condition of the IF, there is not much difference, mainly the bit operators need to each logical operation, and the logical operation will appear short-circuit phenomenon, which can be said to speed up the operation speed.

int  A=3, b=5; A| | b++; b=5//

If statement

Three forms if() { statement }

#include <stdio.h>intMainintargcConst Char*argv[])

{ Charstr; printf ("Please enter: M or f\n"); scanf ("%s",&str); if(str=='m') {printf ("\ n Male"); } Else{printf ("\ n Female"); }}
//
#include <stdio.h>intMainintargcConst Char*argv[]) {        Charstr; printf ("Please enter: M or f\n"); scanf ("%s",&str); if(str=='m') {printf ("\ n Male"); }        Else if(str=='F') {printf ("\ n Female"); }        Else{printf ("\ n Unknown gender"); }            }

Enter a year to determine if leap years

#include <stdio.h>intMainintargcConst Char*argv[]) {        intYear ; printf ("Please enter the year"); scanf ("%d",&Year ); if((year%4==0&&year% -!=0)|| year% -==0) {printf ("is a leap year"); }        Else{printf ("not a leap year"); }        }

Type a character to determine whether it is a letter or

#include <stdio.h>intMainintargcConst Char*argv[]) {printf ("Please enter a character"); CharC; scanf ("%c",&c); if(c< +) {printf ("the control character entered"); }              Else if(c>'0'&&c<'9') {printf ("the input is a number"); }                 Else if(c>'a'&&c<'Z') {printf ("the input is lowercase"); }            Else if(c>'A'&&c<'Z') {printf ("the input is in uppercase"); }             Else{printf ("input is the other"); }    }

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.