-1
#include "avr/io.h"
main()   
{ 
 unsigned char= z  ;  
 for(z=0;z<200;z++) 
  PORTA=z;  //PORTA dispalys the value of z
}

Please explain the working of the loop as z is char and is acting as int

Enkelli
  • 305
  • 5
  • 18
splash
  • 37
  • 1
  • 3
    Please explain *what* about the code. Why it doesn't compile? – Millie Smith Jan 09 '16 at 21:52
  • what i meant was...that how come a char data type can be incremented...for example if i have a char variable like char c=9; and if i increment it what would be the next value....whether it would be an ascii value or 10.....and one more thing this code works absolutely fine...i just had doubt...i hope i have made my question more clearer to you... – splash Jan 12 '16 at 18:00
  • `unsigned char= z ;` compiles? A char data type can be incremented because it's really just a byte. – Millie Smith Jan 12 '16 at 18:04

1 Answers1

1

char (and by extension, unsigned char) is an integral type. An unsigned char can hold values from 0 to 255.

Characters are typically stored in char variables as well. What they actually store is the ASCII value of the character in question. For example:

char c = 'A';

The variable c contains the value 65, which is the ASCII value of A.

In the case of this code, an unsigned char variable is being used in an integer context.

dbush
  • 205,898
  • 23
  • 218
  • 273
  • The range is the minimum range. The standard does not specify an upper bound for `UCHAR_MAX`. Strictly speaking, something like `A` is an [_integer character constant_](http://port70.net/~nsz/c/c11/n1570.html#6.4.4.4p2) and has type `int`. – too honest for this site Jan 09 '16 at 22:29