【问题标题】:Can anyone explain output谁能解释输出
【发布时间】:2013-03-02 14:11:41
【问题描述】:
#define power(a) #a
  int main()
  {
    printf("%d",*power(432));
     return 0;
  }

谁能解释一下o/p??
the o/p is

52

【问题讨论】:

  • 你认为它有什么作用?你有没有努力理解这段代码?这是微不足道的。
  • 我无法理解 '*' 的作用??
  • 在这种情况下,您最需要阅读基本的 C 语言教程。它用于指针解引用。
  • @akash in power(432) => "432"*"432" => "432"[0] => '4' 并且因为 %d 打印了 ascii 值。请记住,我们使用char* ch = "432",这意味着字符串的类型是"432"char*,因此我们可以使用[] 进行索引。正如我们可以做的那样ch[] 您的 macro 将宏函数参数转换为字符串。因为单个 # 运算符。

标签: c macros output printf


【解决方案1】:

相当于:

printf("%d",*"432");

相当于:

printf("%d", '4');

'4' 的 ASCII 值是52

【讨论】:

    【解决方案2】:
    #define power(a) #a   //# is a stringization operation in macro
      int main()
      {
        printf("%d",*power(432));
         return 0;
      }
    
    Hence after calling power(432), macro will return it "432" and applying * on it gives first value which is nothing but 52 (48 + 4) for '4' . 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-12
      • 1970-01-01
      • 2021-02-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多