printf中的指針變量_C語言中的printf()示例/變量

printf中的指針變量

As we know that, printf() is used to print the text and value on the output device, here some of the examples that we wrote to use the printf() in a better way or for an advance programming.

眾所周知, printf()用于在輸出設備上打印文本和值,這里是我們編寫的一些示例,它們以更好的方式或為了進行高級編程而使用了printf() 。

1) Print normal text

1)打印普通文字

printf ("Hello world");

Output

輸出量

Hello world

2) Print text in new line

2)在新行中打印文本

printf ("Hello world\nHow are you?");

Output

輸出量

Hello world
How are you?

3) Print double quote

3)打印雙引號

To print double quote, we use \".

要打印雙引號,我們使用\“ 。

printf("Hello \"World\", How are you?\n");

Output

輸出量

Hello "World", How are you?

4) Print percentage sign (%)

4)列印百分比符號(%)

To print percentage sign/ character, we use %%.

要打印百分比符號/字符,我們使用%% 。

printf ("Hey I got 84.20%% in my final exams\n");

Output

輸出量

Hey I got 84.20% in my final exams

5) Print octal value

5)打印八進制值

To print octal value, we use %o (It's alphabet o in lowercase)

要打印八進制值,我們使用%o (小寫的字母o)

int num = 255;
printf("num in octal format: %o\n", num);

Output

輸出量

num in octal format: 377

6) Print hexadecimal value (with lowercase alphabets)

6)打印十六進制值(使用小寫字母)

To print hexadecimal value, we use %x (its alphabet 'x' in lowercase) - as we know that a hexadecimal value contains digits from 0 to 9 and alphabets A to F, "%x" prints the alphabets in lowercase.

要打印十六進制值,我們使用%x (小寫的字母“ x”)-因為我們知道十六進制值包含從0到9的數字和字母A到F, “%x”以小寫字母打印。

int num = 255;
printf ("num in hexadecimal format(lowercase) : %x\n", num);

Output

輸出量

num in hexadecimal format(lowercase) : ff

7) Print hexadecimal value (with uppercase alphabets)

7)打印十六進制值(使用大寫字母)

To print hexadecimal value, we use %X (it's alphabet X in uppercase) - as we know that a hexadecimal value contains digits from o to 9 and alphabets A to F, "%X" prints the alphabets in uppercase.

要打印十六進制值,我們使用%X (大寫字母X)-因為我們知道十六進制值包含從o到9的數字和字母A至F, “%X”將大寫字母。

int num = 255;
printf ("num in hexadecimal format(uppercase) : %X\n", num);

Output

輸出量

num in hexadecimal format(uppercase) : FF

8) Print long string using \ (slash)

8)使用\(斜杠)打印長字符串

If there is a long string, that you want to print with a single printf() with two or more lines, we can use slash (\).

如果有一個很長的字符串,而您想使用帶有兩行或更多行的單個printf()進行打印,則可以使用斜杠( \ )。

printf ("Hello world, how are you?\
I love C programing language.\n");

Output

輸出量

Hello world, how are you?    I love C programing language.

9) Print backslash (\)

9)打印反斜杠(\)

To print backslash (\), we use double backslash (\\).

要打印反斜杠( \ ),我們使用雙反斜杠( \\ )。

printf ("The file is store at c:\\files\\word_files\n");

Output

輸出量

The file is store at c:\files\word_files

10) To get total number of printed characters

10)獲取打印字符總數

We can also get the total number of printed character using printf(), printf() returns the total number of printed character, that we can store in a variable and print.

我們還可以使用printf()獲得打印字符的總數, printf()返回打印字符的總數,我們可以將其存儲在變量中并進行打印。

int len = 0;
len = printf ("Hello\n");
printf ("Length: %d\n", len);

Output

輸出量

Hello
Length: 6

11) Print integer value 5 digit left padded with 0

11)打印整數值左5位填充0

To print value with 0 padded in 5 digits, we can use "%05d".

要打印以5位數字填充0的值,我們可以使用“%05d” 。

int num = 255;
printf ("num (padded): %05d\n", num);

Output

輸出量

num (padded): 00255

12) Print text with left and right padding

12)使用左右填充符打印文本

To print left padded text with space, we use "%20s" - Here, 20 is the number of characters, if string contains 5 characters then 15 spaces will be added at the left of the text.

要打印帶有空格的左填充文本,我們使用“%20s” -這里的字符數為20,如果字符串包含5個字符,則將在文本左側添加15個空格。

Similarly, to print right padded text with space, we use a flag "-" like "%-20s" - Here, 20 is the number of characters, if string contains 5 characters then 15 spaces will be added at the right of the text.

類似地,要打印帶有空格的右填充文本,我們使用標記“-”,例如“%-20s” -這里的20是字符數,如果字符串包含5個字符,則將在文本右邊添加15個空格。

printf ("str1=\"%20s\", str2=\"%-20s\"\n", "Hello", "World");

Output

輸出量

str1="               Hello", str2="World               "

13) Print float value to specified number of digits after the decimal point

13)將浮點值打印到小數點后的指定位數

To print float value with specified number of digits after the decimal, we use "%.2f". Here, 2 is the number of digits after the decimal point.

要在小數點后打印具有指定位數的浮點值,請使用“%.2f” 。 在此,2是小數點后的位數。

float val = 1.234567;
printf("val = %.2f\n", val);

Output

輸出量

val = 1.23

14) Print integer value with "%i" format specifier

14)使用“%i”格式說明符打印整數值

While printing the value "%d" and "%i" are same, they are used to print an integer value, we can also print the integer value by using "%i".

雖然打印值“%d”和“%i”相同,但是它們用于打印整數值,我們也可以使用“%i”打印整數值。

int num = 255;
printf("num = %i \n", num);

Output

輸出量

num = 255

15) “%p” can be used to print the address of a variable

15)“%p”可用于打印變量的地址

Since, address of the variable is a large hexadecimal value - to print it we should not (or cannot) use "%d", "%i" etc. To print an address of a variable, we must use "%p".

由于變量的地址是一個大的十六進制值-要打印它,我們不應該(或不能)使用“%d” , “%i”等。要打印變量的地址,我們必須使用“%p” 。

int num = 255;
printf("Address of num is: %p\n", &num);

Output

輸出量

Address of num is: 0x7ffca0b5855c

上述所有printf()語句的示例 (Example with all above printf() statements )

#include <stdio.h>
int main()
{
int num = 255;
int len = 0;
float val = 1.234567;
printf("Hello World");
printf("Hello world\nHow are you?");
printf("Hello \"World\", How are you?\n"); 
printf ("Hey I got 84.20%% in my final exams\n");
printf("num in octal format: %o\n", num);
printf ("num in hexadecimal format(lowercase) : %x\n", num);
printf ("num in hexadecimal format(uppercase) : %X\n", num);
printf ("Hello world, how are you?\
I love C programing language.\n");
printf ("The file is store at c:\\files\\word_files\n");
len = printf ("Hello\n");
printf ("Length: %d\n", len);
printf ("num (padded): %05d\n", num);
printf ("str1=\"%20s\", str2=\"%-20s\"\n", "Hello", "World");
printf("val = %.2f\n", val);
printf("num = %i \n", num);
printf("Address of num is: %p\n", &num);
return 0;
}

Output

輸出量

Hello WorldHello world
How are you?Hello "World", How are you?
Hey I got 84.20% in my final exams
num in octal format: 377
num in hexadecimal format(lowercase) : ff
num in hexadecimal format(uppercase) : FF
Hello world, how are you?    I love C programing language.
The file is store at c:\files\word_files
Hello
Length: 6
num (padded): 00255
str1="               Hello", str2="World               "
val = 1.23
num = 255
Address of num is: 0x7ffca0b5855c

翻譯自: https://www.includehelp.com/c-programs/printf-examples-variations.aspx

printf中的指針變量

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/542878.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/542878.shtml
英文地址,請注明出處:http://en.pswp.cn/news/542878.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

System Center Technical Preview DPM(2016)對Exchange2016的災難恢復

其實備份很簡單&#xff0c;就是做好備份計劃即可&#xff0c;但往往客戶最擔心的是備份的東西在真的災難恢復時是否可以恢復出來可用&#xff0c;這才是考驗備份軟件的最關鍵時刻&#xff0c;因此象備份Exchange這樣的應用時對于管理員來說除了會玩備份軟件外還需要熟悉Exchan…

as真機調試_如何使用真機調試android程序

展開全部第一步&#xff1a;將我們開發所用的Android真機的USB調試功能打開(打開方法為Settings(設置32313133353236313431303231363533e59b9ee7ad9431333365656531)Applications(應用程序)Development(開發)勾選USB debugging(USB調試))&#xff0c;然后通過usb連接線連接到開…

css如何制作橫幅,基本的CSS橫幅

我確定這一定非常簡單&#xff0c;但我遇到了問題&#xff01;我想要的效果是每頁上橫幅或標題的純色塊&#xff0c;其中包含一些文字。但是為了增加一些裝飾&#xff0c;我已經為每一面做了一個小圖形&#xff0c;這只是一個從橫幅顏色漸變為白色的小方塊。所以整體效果是一個…

教你在Ubuntu上體驗Mac風格

導讀老實說&#xff0c;我是個狂熱的 Ubuntu 迷&#xff0c;我喜歡 Ubuntu 默認的 Unity 主題樣式外觀。此外&#xff0c;還有很多關于 Ubuntu 14.04 的漂亮圖標主題樣式 可用來美化默認的外觀。但正如我上面提到的仍有很多用戶喜歡 Mac OS X 的主題樣式&#xff0c;我希望這篇…

在Python中升級灰度圖像

Upscaling of an image refers to enlarging the size of an image. 圖像放大是指放大圖像的大小。 In this program, we will be using two functions of OpenCV-python (cv2) module.. lets see their syntax and descriptions first 在此程序中&#xff0c;我們將使用Open…

開機未發現nvidia控制面板_Windows10或者其他操作系統開機提示“未發現NVIDIA控制面板,從Microsoft Store中安裝NVIDIA控制面板”的解決辦法...

昨天深夜,有一個朋友加QQ說他電腦出了問題,不知道咋的就變成了提示“未發現NVIDIA控制面板,從Microsoft Store中安裝NVIDIA控制面板” 里面數據還是挺重要的,問是否有辦法操作,具體看圖; 經過詢問得知,客戶是在安裝一個軟件,反復運行后不出現,以為中毒了,就重啟了一下…

打印機服務器未響應,打印機不能打印,點擊打印后沒反應

①我的電腦&#xff0c;右鍵點管理&#xff0c;服務和應用程序里的服務&#xff0c;找到Print Spooler&#xff0c;啟動類型自動&#xff0c;服務狀態點啟動&#xff0c;確定重啟。②控制面板--》管理工具--》服務---》print spooler改為啟動。③打印機沒設置成為默認打印機&am…

HDU 5145 - NPY and girls

題意&#xff1a; cases T(1≤T≤10) (0<n,m≤30000) (0<ai≤30000)    n個數ai 表示n個女孩所在教室 m次詢問 [L,R]&#xff08;1 < L < R < n&#xff09;   問訪問所有女孩的順序方案數(進教室順序)為多少(一次進教室只能訪問一個人) 分析&…

安卓投屏軟件_有哪些好用又免費的手機投屏到電腦的軟件?

推薦一款免費、好用的投屏軟件&#xff0c;叫做【快投屏】&#xff0c;支持多端無線一鍵投屏、遠程投屏&#xff0c;不限制使用時間&#xff0c;不壓縮投屏畫質。快投屏 - 手機投屏到電視,電腦的無線投屏軟件?支持以下幾種投屏&#xff1a;手機投電視手機投電腦手機投手機電腦…

dnf韓服服務器維護中,DNF2019韓服4.30維護:這些職業被加強

DNF韓服4.30維護DNF2019韓服4.30更新內容 DNF95版本4.30韓服更新內容 DNF95版本職業平衡。相信大家都很想知道吧&#xff0c;一起來看看吧。地下城一直被稱為鬼劍士的游戲&#xff0c;無論是在何地圖&#xff0c;如果看不到鬼劍士的話那就是太陽打西邊出來了&#xff0c;9成勇士…

2019寫給對象的話_戀愛中寫給對象看的說說 2019最流行的情侶間情話

1.我發現你是個照騙&#xff0c;因為本人比照片好看多了。2.我昨晚夢見你了&#xff0c;不知是你想我了還是我想你了。3.你有地圖嗎&#xff0c;我在你的眼睛里迷路了。4.我已經好久沒這樣喜歡一個人了&#xff0c;就是想到你就會笑的那種。5.當自己最愛的人和最愛自己的人是同…

java 實現 堆排序算法_C程序實現堆排序算法

java 實現 堆排序算法Heap Sort is a comparison-based sorting algorithm that makes use of a different data structure called Binary Heaps. Let us understand some important terms, 堆排序是一種基于比較的排序算法&#xff0c;該算法利用稱為二進制堆的不同數據結構。…

嵌入式linux面試題解析(四)——邏輯推理一

嵌入式linux面試題解析&#xff08;四&#xff09;——邏輯推理一1、誰是罪犯問題一位法官在審理一起盜竊案時&#xff0c;對涉及到的四名嫌疑犯A、B、C、D進行了審問。四人分別供述如下&#xff1a;A&#xff1a;“罪犯在B、C、D三人之中。”B&#xff1a;“我沒有作案&#x…

linux rsa登錄改密碼登錄_LINUX中RSA認證登錄SSH(不需要輸入密碼登錄)2種方法

方法一&#xff0c;有的時候經常需要登錄ssh&#xff0c;每次都需要輸入密碼&#xff0c;會比較繁瑣。所以設置了一下使用RSA公鑰認證的方式登錄Linux。首先需要在服務器端設置/etc/ssh/sshd_config# vim /etc/ssh/sshd_config修改如下兩行為yes。其實大多數情況下不用修改&…

b+樹時間復雜度_數據結構:線性表,棧,隊列,數組,字符串,樹和二叉樹,哈希表...

作者&#xff1a;張人大代碼效率優化復雜度 -- 一個關于輸入數據量n的函數時間復雜度 -- 昂貴與代碼的結構設計有著緊密關系一個順序結構的代碼&#xff0c;時間復雜度是O(1), 即任務與算例個數 n 無關空間復雜度 -- 廉價與數據結構設計有關數據結構 -- 考慮如何去組織計算機中…

figure服務器無法顯示,求大神幫幫忙,看一下為什么第二個figure出不來,只能顯示第一個...

該樓層疑似違規已被系統折疊 隱藏此樓查看此樓Iimread(C:\Users\Administrator\Desktop\123.jpg);figure(1)subplot(3,2,1),imshow(I), title(原始圖像);I1rgb2gray(I);subplot(3,2,2),imshow(I1),title(灰度圖像);I2edge(I1,roberts,0.09,both);subplot(3,2,3),imshow(I2),tit…

python 示例_帶有示例的Python File read()方法

python 示例文件read()方法 (File read() Method) read() method is an inbuilt method in Python, it is used to read the content of the file, by using this method we can read the specified number of bytes from the file or content of the whole file. read()方法是…

評價最高影片JAVAlibrary_視頻 | 手游大神,動畫導演,機圈新貴,極客怎么評價《憤怒的小鳥2》?...

誰能想到&#xff0c;迄今為止口碑最好的「游戲改編電影」竟然來自一個手機游戲IP&#xff1f;&#xff01;《憤怒的小鳥2》是有史以來評價最好的游戲改編電影。—— http://Screencrush.com《憤怒的小鳥2》憑什么能在打分平臺上獲得游戲改編電影最高分&#xff1f;—— http:/…

如何安裝_如何安裝吸頂燈?吸頂燈安裝注意事項

摘要&#xff1a;燈是我們每個家庭都有的照明裝置&#xff0c;它的造型和光能效果能直接影響到家居生活的氛圍、美觀度以及健康狀況。吸頂燈的造型功能也隨著科技的發展在不斷發生多元化的改變。如今市面上的吸頂燈既有簡單的裝置又不比吊燈少了時尚奢華&#xff0c;讓在層高較…

win10虛擬網絡服務器,win10 虛擬專用網絡服務器配置

win10 虛擬專用網絡服務器配置 內容精選換一換本節將介紹在華為云關系型數據庫服務的管理控制臺創建實例的過程。目前&#xff0c;RDS for SQL Server支持“包年/包月”和“按需計費”購買&#xff0c;您可以根據業務需要定制相應計算能力和存儲空間的華為云關系型數據庫實例。…