我需要一个以下客观问题的答案 [英] I need an answer for below objective question

查看:61
本文介绍了我需要一个以下客观问题的答案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查找以下程序的输出



int a;

a ='b' - 'a';

printf(%d \ n,a);



a)编译错误

b)97

c)98

d)0



我的尝试:



起初我认为输出将是1作为ASCII值的减法。但是在执行时它会给出错误。因为我是C的初学者。希望你能帮帮我!!

解决方案

我得到的解决方案就是我所期待的:1

那是使用两个不同的编译器:

Virtual-C IDE [ ^ ]



在线C编译器 - 在线编辑器 [ ^ ]

两者都给出相同的结果。



我不能想一想会(或应该)给出错误或任何其他结果的编译器!

我会仔细检查这个问题并确保你没有错过任何东西或在这里输入错误。


你提出的代码完全有效 C 一。以下程序

  #include   <   stdio.h  >  

int main()
{
int a;
a = ' b' - ' a';
printf( %d \ n,a);
return 0 ;
}



编译('无警告')并且运行正常,产生输出

 1 


Find output of below program

int a;
a= 'b' - 'a';
printf("%d\n",a);

a) compilation error
b) 97
c) 98
d) 0

What I have tried:

At first i thought the output would be 1 as the subtraction of ASCII values.but on execution it is giving errors. Since i am a beginner in C. Hope you will help me out !!

解决方案

The solution I get is what I'd expect: 1
That's using two different compilers:
Virtual-C IDE[^]
And
Online C Compiler - online editor[^]
Both give the same results.

I can't think of a compiler that would (or should) give an error or any other result!
I'd check the question really carefully and make sure you haven't missed something or mistyped it here.


The code you poste is perfect valid C one. The following program

#include <stdio.h>

int main()
{
  int a;
  a= 'b' - 'a';
  printf("%d\n",a);
  return 0;
}


compiles ('warninglessly') and runs fine, producing the output

1


这篇关于我需要一个以下客观问题的答案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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