C language data type (ii)

Source: Internet
Author: User

Char type

1.char Variable Constants

char c; Define a char variable

c = ' A ' A ' a ' character constant

The essence of char is an integer, with only one byte-sized integer

2.printf Output Char

%c means to output a character instead of an integer

3. Do not look print char transfer character

\a Alarm

int Main () {    char'\a';    printf ("%c\n", c); // ring a sound    return 0 ;}

\b Backspace

\ nthe line break

\ r Enter

\ t tab

\ \ Slash

\ ' Single quotation mark

\ "Double quotation marks

\? Question mark

\ n is a newline, which means that the cursor is moved down one cell

  \ is carriage return, indicating that the cursor is to the beginning of

\ r \ n indicates carriage return line

4 Char and Unsiged Char

char a = 0; Defines a signed

Unsiged Char defines an unsigned char

  

-124

floating-point float double long double type

1. Floating-point constant variable

Float in a 32-bit system 4 bytes

Double on a 32-bit system 8 bytes

Floating point number is not efficient, avoid using floating point number

Floating-point numbers are paid to integers and only integers are retained

Rounding Direct plus 0.5 to integer

#include <stdio.h>int  main () {    int5;     5 2 ;
Double F = 4; Floating point numbers are not efficient, avoid using floating-point printf ("%d"// integers cannot retain digits after the decimal point return0;}

2.printf output Floating point number

.%f

Type Restrictions

Const represents a constant that cannot be changed

A volatile variable is one that may be changed outside of the CPU instructions.

 #include <stdio.h>int   main () { volatile  int  i = 100 ; //     Tell the editor not to optimize code i + = for this variable;     i = i + 5  ;  //  External device changed the value of i  i = i + 10  ;    I  = i + 30  ; printf (  " %d\n   "    , I);  return  0  ;}  

Register

This is a suggested directive, not a command-line directive.

Register int i = 100;//i not in memory, directly inside the register of the CPU

  

string format output input

"" is the way the C language expresses the string

The essence of a string is the character

 

Putchar Print one character

Putchar (' A ')->asc yards

SCANF read the user input through the keyboard, put into the variable, remember the parameter must be the address of the variable (&)

#include <stdio.h>int  main () {    int a=0, b=0;    scanf ("%d", &a);    scanf ("%d", &b);    printf ("a+b=%d", A +b)    ; return 0 ;}

GetChar to get the user keyboard input characters

#include <stdio.h>int  main () {    char0;     = GetChar ();    printf ("%c", a);     return 0 ;}

C language data type (ii)

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.