Originally Posted by
Bracer
4 pointers to char, ok.....but each char is just one character right ?
Yes
Originally Posted by
Bracer
Why is it that the minute the pointer points at a char data type it magically become this modern string instead of being what it is ? A single character holder ?
It is not so much magic as the standard convention that a string in C is a "contiguous sequence of characters terminated by and including the first null character". This means that given a pointer to the first char in a string, you can obtain all the chars of the string by pointing to the next character, and the next, etc, until you reach the null character.
Originally Posted by
Bracer
P:S, 12 is correct, run this program
Your program prints the length of the string, but this program prints the number of characters required to store the string in an array:
Code:
#include <stdio.h>
int main(void)
{
printf("The Length of the \"Hello World\" is %u .\n", sizeof("Hello World\n"));
return 0;
}
By the way, use #include instead of the non-standard #import.
Also, try this variant of your program:
Code:
#include <stdio.h>
#include <string.h>
int main(void)
{
char variable[12] = "Hello World\n";
char x[] = "abc";
printf("The Length of the \"Hello World\" is %d .\n", strlen(variable));
return 0;
}
If you still get 12 as the length of the string, I'll change it such that you don't.