Negative ascii codes

negascii.c

ascii codes. From the link, one can say that the ascii codes are non-negative values. Correct. However, the following code seems to confuse some people. The case is that C assigns negative values to the variable of type char, because in C/C++ integral values have a finite limit. For example a signed char can only hold numbers in the range of -128 to 127.

#include<stdio.h>
int main(void)
{
    char a='A';
    while(a)
    {
        printf("%d = %c\n", a, a);
        a++;
    }
    /* 0 is NULL */
    printf("%d = NULL", a);
    return 0;
}

which outputs:

65 = A
66 = B
67 = C
68 = D
69 = E
70 = F
71 = G
72 = H
73 = I
74 = J
75 = K
76 = L
77 = M
78 = N
79 = O
80 = P
81 = Q
82 = R
83 = S
84 = T
85 = U
86 = V
87 = W
88 = X
89 = Y
90 = Z
91 = [
92 = \
93 = ]
94 = ^
95 = _
96 = `
97 = a
98 = b
99 = c
100 = d
101 = e
102 = f
103 = g
104 = h
105 = i
106 = j
107 = k
108 = l
109 = m
110 = n
111 = o
112 = p
113 = q
114 = r
115 = s
116 = t
117 = u
118 = v
119 = w
120 = x
121 = y
122 = z
123 = {
124 = |
125 = }
126 = ~
127 = 
-128 = €
-127 = �
-126 = ‚
-125 = ƒ
-124 = „
-123 = …
-122 = †
-121 = ‡
-120 = ˆ
-119 = ‰
-118 = Š
-117 = ‹
-116 = Œ
-115 = �
-114 = Ž
-113 = �
-112 = �
-111 = ‘
-110 = ’
-109 = “
-108 = ”
-107 = •
-106 = –
-105 = —
-104 = ˜
-103 = ™
-102 = š
-101 = ›
-100 = œ
-99 = �
-98 = ž
-97 = Ÿ
-96 =  
-95 = ¡
-94 = ¢
-93 = £
-92 = ¤
-91 = ¥
-90 = ¦
-89 = §
-88 = ¨
-87 = ©
-86 = ª
-85 = «
-84 = ¬
-83 = ­
-82 = ®
-81 = ¯
-80 = °
-79 = ±
-78 = ²
-77 = ³
-76 = ´
-75 = µ
-74 = ¶
-73 = ·
-72 = ¸
-71 = ¹
-70 = º
-69 = »
-68 = ¼
-67 = ½
-66 = ¾
-65 = ¿
-64 = À
-63 = Á
-62 = Â
-61 = Ã
-60 = Ä
-59 = Å
-58 = Æ
-57 = Ç
-56 = È
-55 = É
-54 = Ê
-53 = Ë
-52 = Ì
-51 = Í
-50 = Î
-49 = Ï
-48 = Ð
-47 = Ñ
-46 = Ò
-45 = Ó
-44 = Ô
-43 = Õ
-42 = Ö
-41 = ×
-40 = Ø
-39 = Ù
-38 = Ú
-37 = Û
-36 = Ü
-35 = Ý
-34 = Þ
-33 = ß
-32 = à
-31 = á
-30 = â
-29 = ã
-28 = ä
-27 = å
-26 = æ
-25 = ç
-24 = è
-23 = é
-22 = ê
-21 = ë
-20 = ì
-19 = í
-18 = î
-17 = ï
-16 = ð
-15 = ñ
-14 = ò
-13 = ó
-12 = ô
-11 = õ
-10 = ö
-9 = ÷
-8 = ø
-7 = ù
-6 = ú
-5 = û
-4 = ü
-3 = ý
-2 = þ
-1 = ÿ
0 = NULL

This code is developed by me, G. Samaras.

Have questions about this code? Comments? Did you find a bug? Let me know!😀
Page created by G. (George) Samaras (DIT)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s