Let us learn C in Code _printf()_function

Ok, let's review the previous chapters, all the main() function just followed some variables and equation, for example 

main()

{

int a = 1;

int b  = 2;

int c = 0;

c = a + b;

}

We know the result is 3 ,surely c equals 3. Actually when this program is complied and linked , the variable c is 3 , but if a and b are big numbers ,like "a = 246524" and "b = 34532465", can you tell me the result immediately as you see that? I don't know whether u can or not, but i can't. Because i'm not a genius. But actually , when we write them as a program, then compile and linked it. The result just hold in the variable c as above program. My pc knows the result, but i don't . How can i let the pc tell me the the result?Let's us use the function of printf().

The printf() function is one fo the  predefined standard C functions. The basic purpose is used to print some useful information between the quotation marks like table belows , printf() function just output  these characters.

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

printf() function                                                    output 

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

printf("Hello everyone!");                             Hello everyone!

printf("ERROR!");                                          ERROR!

printf("a: b: c:");                                              a: b: c:

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


At "Let us learn C in Code <3>" we have refer with some special characters which are composed by two characters but actually represent one character.  So if we let the printf() function output these special characters , what happened? Don't afraid there is not  boooom,  u can't destroy ur computer ,too. Just try them,  before doing that let's list these special constant characters ,please refer to the below table.

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

constant           meaning

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

'\n'                    newline

'\a'                    alert (sound)

'\r'               carriage return

'\0'                 null

'\"' double quote

'\'' single quote

....                                 ....

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


I don't list all of the special characters, these list above are used frequently. Just try them in our program , for example

main()

{

int x = 2;

int y = 0;

y = (x*x) +(2*x) +1

printf("Now,x equal 2 and  the value of y is \n\a");

}

Time limited, the above program is just the one answer of the "Let us learn C in Code <4> data type" mentioned.  Have a nice day every one, I hope u enjoy it. See you next chapter!


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章