0
[check the description] : does the strinig terminator "\0" included before x since i used i<8, but while printing it, the output
CODE : int main() { char firstName[] = "ANIRBAN"; for (int i = 0; i < 8; i++) { printf("%c \t", firstName[i]); } printf("%c", 'x'); return 0; } OUTPUT : A N I R B A N x
4 Respuestas
+ 4
Print firstName[ i ] as char and integer to find out whether the null terminator was also printed.
printf("%c (%d)\t", firstName[i], firstName[i]);
But as you probably know already, null terminator is non printable character, thus you won't likely see any character prior to the '(0)' printed by '(%d)' format specifier.
And iterating a string past its length is not a safe thing to do, so evade it best you can ...
+ 1
Glad you got it figured out 👌
0
Can you point out what's wrong? In this code every character in the array is printed separated by a space character and a tab character (\t). Because of the null-terminator, after 'N' there is double the space (" \t \t"), probably causing the 'x' going on newline because of all the spacing before
0
@Ipang i tried it....and actually it works ...
this is the output : A (65) N (78) I (73) R (82) B (66) A (65) N (78) (0) x