"==" question?

if z is an int and z=8
why would z=='8' be false?
Single quotes imply it's a character. So when you try z == '8', you're trying to compare a variable int to a char. z == 8 is how you would compare a variable int to an int.
closed account (1CfG1hU5)
a very simple example using z.

1
2
3
4
5
6
7
8
9
10
11
#include <stdio.h>

int main()
 {
  int z = 8;

  if (z == 8) 
   printf("the value stored in z is %d", z);  // very simple output because of z's truth.

  return 0;  // returns value because main() is of integer type.
 }

Last edited on
Topic archived. No new replies allowed.