This site is about programming(mostly) things I either do or am learning.
10 Mar 2018 | | C
“Ok…this is a weird one…”
There is no string type in C. They are defined as an array of characters. The difference between a string and a character array is that a string has the special character ‘\0’ in it’s last position.
Example program defining and using a string as a parameter
#include<stdio.h>
int main()
{
// declaring string
char str[50];
// reading string
scanf("%s",str); // look ma no &str!
// print string
printf("%s",str);
return 0;
}
C the Weird Parts Book : the scanf function takes a pointer to its parameter, but in the code above an ‘&’ which defines a pointer is not required, because a string is an array, and the variable str without the brackets [] represents the base address of the string array. Weird.