C's Diary-printf and scanf

Source: Internet
Author: User

------------------------------------------------------------------------------------
the distinction between printf and scanf

& is a fetch address character, &a represents the address of variable A.
scanf ("%d", &a); Indicates that receiving an integer from the keyboard is stored in memory to the address referred to in &a, which is the variable A.

&a represents the address of a variable in memory, which is the address of a in memory space;
&a Address: The address of the storage byte, where the value of variable A is stored, that is, in variable a.
scanf ("%d", &a), refers to the contents of the input into a memory space where the address points to the byte storage address, that is, the input content is assigned to A;
scanf ("%d", a), is to place the input content into the address of the memory space where A is located, the address is compiled system allocation, so that changes the memory space address, the danger;
printf ("%d", a); means assigning the contents of a to%d to print;
printf ("%d", &a); means assigning the address of a to%d printing;
Two the difference is because the value in printf, just give the current value out of the good,
In scanf, the value after "%d" refers to the place where the input data is to be deposited, the next level of the value, or where the value is pointing.

-----------------------------------------------------------------------------------

1. Standard input and OUTPUT functions
Putchar.
<1>putchar function is to output a character to the terminal, even if the Putchar (a, b) can only output the first character
Putchar can only output character variables, other variable output will be error, but this character type variable can be equal to the shape of the
such as Char C=65;putchar (c), or Putchar (97);
and int C=65;putchar (c); is wrong, but coercion type conversion putchar ((int) c);
Putchar (' 101 ') can output 1 because 1 is also an ASCII character.
Putchar (' \101 ') can output a because it outputs an escape character.
Putchar (' \ \ ') can output \ characters. Putchar (92); can also output \ characters.
-----------------------------------------
On the whole, all the characters that can be output are present in the ASCII table, but because of the symbolic problem of the compiling system, some symbols such as ' \ can't be output directly, because the compiling system will error, so we use the escape character output, namely: Putchar (' \? '); The question mark in this can be either the number 0-255 or the ' \ Symbol
The escape character means replacing the current character with another representation in the ASCII code table and outputting it!!
For example: Putchar (' \101 ') =putchar (101) =putchar (' A ') and Putchar (' \ \ ') =putchar (92)
The true meaning of an escape character is to convert the character following the escape character to the value of the ASCII code to output.

A variable is a value stored in an address of memory that can be changed.
The variable name is how you use the address in your program, giving him a name.
The variable name actually represents a memory address with a name, and when the compiler works, it assigns memory addresses and spaces to each variable name, such as a char to allocate 1 bytes, and 0/1 encoding in that byte to represent 0-255 characters. Change the value of the variable, in fact, the variable name to find the memory address of the variable, and then the address of the storage unit to remove the current 0/1 encoding to operate.
-----------------------------------------
Assigning a character constant to a char variable does not actually place the character itself in the memory unit, but instead puts the ASCII tag of the character into the memory unit, outputs it as a character, converts it to output, and outputs it directly!
-----------------------------------------
When we output the variable name, Putchar (a) actually does is to find the memory address through the variable name A and take out the value (ASCII value) in the Address storage unit.
The Putchar (' a ') is a direct output value.
Go down the Putchar (' a ') process: Compile the system compiled by, compile into binary intermediate file, then the system assigns a nameless 1 bytes memory space, the value of this space is 65. Then the operating system to connect the library file, knowing that the output format of the char type, the value is converted to a character, and then printed to the output device, the temporary space is emptied.


-----------------------------------------------------------------------------------
Comprehensive:
Char A=65/char a= ' A ' memory is stored in 65
Putchar (a) is to find the address of a storage space value, the char type of formatted output, the output is a
Putchar (96) is actually no space storage, it is directly convert 96 to binary code output corresponding character '
Putchar (' ABCDADF ') is a temporary open nameless memory, only 651 digits in memory, the output is a
Putchar (' 101 ') ibid, because 1 is also a character, except that the number in memory has changed
Putchar (' \101 ') escape character, originally memory can only be stored in 1 corresponding code, but \101 open up memory when 101 becomes the value of storage, now in memory 101, the output becomes 101 corresponding characters
Putchar (' \ \ ') on the basis of the open memory when the \ corresponding ASCII code value into a stored value, so that the output when the output character \, if not to do so, the execution system can not directly output \ Character, the compilation system will error
Putchar (' \1011 ') 1011 more than 255 when the escape character opened up memory, so the storage space cannot be stored, and this escape character does not work, essentially =putchar (' 1011 ')
-----------------------------------------------------------------------------------

C's Diary-printf and scanf

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.