Strings are nothing more than arrays of characters, with a null
character at the end, '\0'.
#include <stdio.h>
void hard( void ) {
char hello[6];
hello[0] = 'H';
hello[1] = 'e';
hello[2] = 'l';
hello[3] = 'l';
hello[4] = 'o';
hello[5] = '\0';
printf( "%s\n", hello );
}
void easy( void ) {
char world[] = "world";
printf( "%s\n", world );
printf( "world[] is %lu bytes\n", sizeof( world ) );
}
int main( void ) {
hard();
easy();
return 0;
}
Hello world world[] is 6 bytesTOC | Prev | Next