Home > Backend Development > C#.Net Tutorial > What symbols are used to output strings in C language?

What symbols are used to output strings in C language?

王林
Release: 2020-06-19 15:03:09
Original
14969 people have browsed it

What symbols are used to output strings in C language?

#Use double quotes in C language to output strings.

(Recommended tutorial: c language tutorial)

Detailed interpretation:

In C language, there are two functions that can be controlled Output strings on the computer (monitor), they are:

puts(): Output strings and automatically wrap lines. This function can only output strings.

printf(): Outputs a string through the format control character %s, and cannot automatically wrap lines. In addition to strings, printf() can also output other types of data.

For example:

#include <stdio.h>
int main(){
    char str[] = "http://c.bian";
    printf("%s\n", str);  //通过字符串名字输出
    printf("%s\n", "http://c.bian");  //直接输出
    puts(str);  //通过字符串名字输出
    puts("http://c.bian");  //直接输出

    return 0;
}
Copy after login

Note that when outputting a string, you only need to give the name, without the following [ ]. For example, the following two ways of writing are wrong:

printf("%s\n", str[]);
puts(str[10]);
Copy after login

The above is the detailed content of What symbols are used to output strings in C language?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template