C getting started tutorial 2nd values, characters, and strings

Source: Internet
Author: User

Declaration method:

Data type variable name;

Example:

// Int type int I;/* General Declaration */int j, k;/* multiple declarations at the same time */int age = 18; /* simultaneous assignment of declarations */int Alan, Sam = 16;/* declaration and simultaneous assignment * // float Type float f;/* Common Declaration */float q, money;/* declare multiple at the same time */float v = 2.0;/* assign a value at the same time * // char c of the char type;/* Common Declaration */char zh, text;/* declare multiple at the same time */char letter = 'a';/* assign values at the same time * // char array (string) char c [20] = {'h', 'E', 'l', 'l', 'O', '', 'w', 'O ', 'R', 'l', 'D'}; char name [] = {'A', 'l', 'A', 'n '};

 

Escape characters

Characters that must be escaped and cannot appear directly in a string

'\ N' line feed

'\ T' horizontal tabulation

'\ ''Single quotes

'\ "' Double quotation marks

'\' Backslash

#include<stdio.h>main(){    printf("Num\tName\n");    printf("001\tAlan\n");    printf("002\tLellansin\n");}

Output result:

Num Name

001 Alan

002 Lellansin

 

Printf and scanf

Printf print, scanf is input

Printf (string ,...);

Scanf (string ,...);

 

For example:

 

Printf ("Alan's age is % d", age );

Scanf ("% d", & I );

 

Example:

# Include <stdio. h> main () {int age; printf ("What is your age? \ N "); scanf (" % d ", & age); printf (" your age is % d ", age );}

Common formats:

% D decimal integer

% I decimal integer

% C single character

% S string

% F floating point number

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.