One: C language (data types and operators)

Source: Internet
Author: User
Tags ming

1#include <stdio.h>/*is a pre-processing command, its role is to inform the C compiler system in the C program before the formal compilation needs to do some preprocessing work. */2    intMain ()The /*c program executes the code in the main function, or it can be said that the main function is the only entry in the C language. */3 {4printf"I Love imooc!");/*See if the print statement here is correct*/  5     return 0;6}

Two: Data type

1 #include <stdio.h>2int  main ()3{4      int  age=;  /* define the age variable */5     printf (" I am%d this year!") \ n", age); 6     return 0 ;     7 }

C Language Support data types

Formatted output

    

1#include <stdio.h>2 intMain () {3     intAge = -;4     floatHeight =1.85;5     CharUnit ='m';6printf"Xiao Ming is%d years old \ n", age);7printf"Xiao Ming's height%f%c\n", height, unit);8printf"Xiao Ming is now learning it technology on the Internet in MU class"); 9     return 0;Ten}

Defining constants

1#include <stdio.h>2 3 #definePocketmoney 10//defining constants and constant values4 intMain ()5 {6    //Pocketmoney = 12; //does Xiao Ming increase his pocket money privately? 7printf"Xiaoming got%d dollars in pocket money again today \ n", Pocketmoney);8     return 0; 9} 

Automatic conversion type

1#include <stdio.h>2 intMain ()3 {4     Charc ='a';5     intn = C;//Assign c to n6     floatf = C;//Assign c to f7     DoubleD = C;//Assign c to D8printf"%d\n", n);9printf"%f\n", f);Tenprintf"%lf\n", d); One     return 0;  A}

  Forced conversions

 1  #include <stdio.h>2  int   Main ()  3  { 4  double  num = 2.5 ; //  5  printf ( " num is%d\n  , (int  )  NUM); Cast to int output 2  6  return  0  ;  7 } 

Three: operator

Note In the division operation:

If the two digits of the division are integers, then the result is an integer, the fractional part is omitted, such as 8/3 = 2, and two is a decimal , and The result is a decimal number, such as: 9.0/2 = 4.500000.

Take note of the remainder operation:

This operation is only suitable for two integers , such as: 10%3 = 1, while 10.0%3 is wrong; The post-op symbol depends on the symbol being modulo, such as (-10)%3 =-1; and 10% (-3) = 1.

Note: The C language does not have the exponentiation operator, nor can it use arithmetic symbols such as x,÷.

Assignment Operators

+ =,-=, *=,/=,%=

  Comparison operators

  logical operators

  Trinocular operator

1#include <stdio.h>2 intMain ()3 {4     //define the money in the small pocket5     DoubleMoney = A     ; 6     //define the cost of a taxi home7     DoubleCost =11.5      ; 8printf"Small series can take a taxi home:"); 9     //Output y small series on a taxi home, output n Small series can not take a taxi homeTenprintf"%c", Money>cost?'y':'N'            ); One     return 0; A}

One: C language (data types and operators)

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.