C language if(word==apple) gets a message that the identifier apple is not defined

Asked 1 weeks ago, Updated 1 weeks ago, 2 views

//1 code
int num1;
printf ("Number Entry");
  printf ("The number entered is 1";
return 0;
//2 Code
char word;
printf ("Character Input");
If(word==apple)//This message indicates that the identifier apple is not defined.
  printf ("The character you entered is an apple";
return 0;

I want to know exactly why code 1 runs normally, but code 2 doesn't work. I understand that computers process data in binary, but is it related to that? I'm asking you a question because I can't answer it alone.


2022-09-20 15:05

1 Answers

The reason why code number 2 is getting an error is because the apple is not declared.

Code 1 compares num1 to number 1, and number 1 is just number 1 in code. So you don't have to declare 1 separately.

By the way, in code 2, the word is compared to apple, but in the code I showed you in the question, there is no apple declaration. I think it might have been missing while I was writing it down, but the reason why there is an error is because there is no declaration of apple.

If there was a line char apple='a'; at the top of code 2, and the user entered a, the printf("The letter you entered is an apple."); statement will be printed.

2022-09-20 15:05

If you have any answers or tips

© 2022 pinfo. All rights reserved.