Learn from Yin Cheng and C + + 006

Source: Internet
Author: User

Characters and strings
Characters according to%d, print asccii
Characters Press%c to print the characters themselves
' 0 ' 0 ' + ' difference:

Char ch3=0; The equals sign is automatically converted to the character that corresponds to the ASCCII value. That is, null or
C string cannot be added directly

String%s

sprintf printing to a string
#include <stdio.h>
#include <stdlib.h>
void Main1 ()
{
char ch = ' A ';
Putchar (CH);
printf ("%c", ' A ');

GetChar ();
}
void Main2 ()
{
char ch = ' A ';
wchar_t WCH = L '; Wide character ' A ' in order to be compatible with extended wide characters, typically 4 bytes, but assigned to CH for 1 bytes
System ("color 4f");
System ("title Liu Mitong");
System ("pause");


The string/0 ends, equal to each character, and the tail is added ' s '.

}
void Main ()
{
char ch = getchar ();
if (ch >= ' A ' &&ch <= ' Z ')
{

CH = ch + 32;
}
Putchar (CH);
System ("pause");


}
Create a variable symbol table
Real numbers do not seek remainder


Data type conversions

printf ("%d", (int) 12.1);
printf ("%f", (float) 10);

printf is not automatically converted, int converts integers

Automatic type conversion of operations between different data types


Forcing type conversions

float a1=10.8;
float a2=10.3;
int num= (int) a1+a2;
int num2= (int) (A1+A2);


Large data types to small conversion accuracy will be lost

printf ("%.2f", db); Show only two digits after the decimal point


Memory principles for data type conversions

Data loss occurs with big data int to Char

unsigned int cannot be assigned a negative number

Being able to compile does not mean that the result is correct

scanf%LF corresponds to double

Learn from Yin Cheng and C + + 006

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.