\\%和%%之间的区别 [英] Difference between \% and %%

查看:2313
本文介绍了\\%和%%之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读过一些K&放后,R C,我看到的printf可以认%%为自己我测试了这一点,它打印出%,我又试图\\%,这也印有%。

After reading over some K&R C I saw that printf can "recognize %% for itself" I tested this and it printed out "%", I then tried "\%" which also printed "%".

那么,有什么区别呢?

编辑为code要求:

#include <stdio.h>

int main()
{
  printf("%%\n");
  printf("\%\n");
  return 0;
}

输出:

%                                                                               
%  

使用-o使用GCC编译

Compiled with GCC using -o

版本的GCC:GCC(的SUSE Linux)4.8.1 20130909 [GCC-4_8-分支修订202388]

GCC version: gcc (SUSE Linux) 4.8.1 20130909 [gcc-4_8-branch revision 202388]

推荐答案

%% 是不是C转义序列,但一个printf格式化像个为自己逃生特殊字符。

%% is not a C escape sequence, but a printf formatter acting like an escape for its own special character.

\\%是非法的,因为它有一个C转义序列的语法,但没有明确的意义。转义序列除了列为标准少数是编译器特定的。在所有的可能性编译器忽略反斜线和的printf 没有看到在运行时的任何反斜线。如果有,它会在打印输出中的反斜杠反斜杠因为没有特别的的printf

\% is illegal because it has the syntax of a C escape sequence, but no defined meaning. Escape sequences besides the few listed as standard are compiler-specific. In all likelihood the compiler ignored the backslash, and printf did not see any backslash at runtime. If it had, it would have printed the backslash in the output, because backslash is not special to printf.

这篇关于\\%和%%之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆