T
Tagore
I found following program in a C forum:
----------------------------
#include<stdio.h>
int main()
{
char i;
for (i=0;i<=120;i+=10)
printf("%d\n",i);
}
------------------------
there were 2 reply to this question:
1st reply: It was in sync with my solution. It said that it repeat 38
times due to overflow from 120 to -126 as possible range of char is
from -128 to 127.
2nd reply: It quoted this program as having undefined behaviour as C
does not specify data type "char" is signed or unsigned.
I tried to run above program and it did print 38 lines. when I changed
char to unsigned char, it printed only 13 times.
Which of above reply is correct? Does by default C not have signed
char?
----------------------------
#include<stdio.h>
int main()
{
char i;
for (i=0;i<=120;i+=10)
printf("%d\n",i);
}
------------------------
there were 2 reply to this question:
1st reply: It was in sync with my solution. It said that it repeat 38
times due to overflow from 120 to -126 as possible range of char is
from -128 to 127.
2nd reply: It quoted this program as having undefined behaviour as C
does not specify data type "char" is signed or unsigned.
I tried to run above program and it did print 38 lines. when I changed
char to unsigned char, it printed only 13 times.
Which of above reply is correct? Does by default C not have signed
char?