C language--operators, branching structures, looping structures

Source: Internet
Author: User
Tags logical operators strcmp

One, operator

Relational operators

Relational Operators meaning the expression in mathematics
< Less than <
<= Less than or equal to
> Greater than >
>= Greater than or equal to
== Equals =
!= Not equal to

Conditional operators

max = (a>b)? A:B;

  

logical operators

operator Description Binding Nature Example
&& and arithmetic, binocular, corresponding to the "and" in mathematics Left combination 1&&0, (9>3) && (b>a)
|| or arithmetic, binocular, corresponding to the "or" in mathematics Left combination 1| | 0, (9>3) | | (B>a)
! Non-arithmetic, monocular, corresponding to "non" in mathematics Right combination !a,! (2<5)

Two, branch structure

If Else

Non-bint in (Char *str) {char *str1= "a";p rintf ("strcmp (str, str1):%d\n", strcmp (str, str1)); if (strcmp (STR,STR1) ==0) { return 1;} else{    return 0;}}

Switch

Satisfies the case condition: there is a break that jumps out of the loop, and no break resumes execution of subsequent non-satisfied case conditions.

#include <stdio.h>int main () {    int A;    printf ("Input integer Number:");    scanf ("%d", &a);    Switch (a) {case        1:printf ("monday\n");        Case 2:printf ("tuesday\n"); break;        Case 3:printf ("wednesday\n"); break;        Case 4:printf ("thursday\n"); break;        Case 5:printf ("friday\n"); break;        Case 6:printf ("saturday\n");         Case 7:printf ("sunday\n");         default:printf ("error\n");     }    return 0;}

 

Third, the cycle structure

For

Break jumps out of the loop

 

int arr1 (int n,int arr[]) {for (int i=0;i<n;i++) printf ("%d", Arr[i]); return arr[i];}

  

  

C language--operators, branching structures, looping structures

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.