在 C 语言中,%s 用于格式化字符串,在字符串中插入变量或表达式。语法:printf("%s", str); str 是要插入的字符串变量或表达式。用法包括:打印字符串、打印变量和打印格式化字符串。
%s 在 C 语言中的用法
%s 是 C 语言中格式化字符串的占位符。它用于在字符串中插入变量或表达式。
语法:
printf("%s", str);
其中:
立即学习“C语言免费学习笔记(深入)”;
用法:
示例:
#include <stdio.h> int main() { char name[] = "John"; int age = 30; // 打印字符串 printf("My name is %s.\n", name); // 打印变量 printf("My age is %d.\n", age); // 打印格式化字符串 printf("I am %d years old and my name is %s.\n", age, name); return 0; }
输出:
My name is John. My age is 30. I am 30 years old and my name is John.
注意:
以上就是%s在c语言中的用法的详细内容,更多请关注php中文网其它相关文章!
C语言怎么学习?C语言怎么入门?C语言在哪学?C语言怎么学才快?不用担心,这里为大家提供了C语言速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号