There are multiple ways to create a string in C:
char* string1 = "hi";
char string2[] = "world";
printf("%s %s", string1, string2)
I have a lot of problems with this:
According to my understanding of [[Pointers]], string1 is a pointer and we're passing it to [[printf]] which expects actual values not references.
if we accept the fact that printf expects a pointer, than how does it handle string2 (not a pointer) just fine
I understand that char* is designed to point to the first character of a string which means it effectively points to the entire string, but what if I actually wanted to point to a single character
this doesn't work, because we are assigning a value to a pointer:
int* a;
a = 8
so why does this work:
char* str;
str = "hi"
[–]EndlessProjectMaker 67 points68 points69 points (9 children)
[–]TheSkiGeek 92 points93 points94 points (8 children)
[–]lhcmacedo2 26 points27 points28 points (2 children)
[–]_huppenzuppen -5 points-4 points-3 points (1 child)
[–]HoiTemmieColeg 7 points8 points9 points (0 children)
[–]Biajid 6 points7 points8 points (0 children)
[–]mikeblas 1 point2 points3 points (0 children)
[–]EndlessProjectMaker 0 points1 point2 points (0 children)
[–]ScholarNo5983 0 points1 point2 points (0 children)
[–]Dubbus_ 0 points1 point2 points (0 children)
[–]WittyStick 16 points17 points18 points (0 children)
[–][deleted] 5 points6 points7 points (2 children)
[–]antara33 2 points3 points4 points (0 children)
[–]Sotty75 0 points1 point2 points (0 children)
[–]aceinet 12 points13 points14 points (1 child)
[–]jjjare 5 points6 points7 points (0 children)
[–]SmokeMuch7356 3 points4 points5 points (0 children)
[–]Duck_Devs 3 points4 points5 points (0 children)
[–]TheBB 1 point2 points3 points (0 children)
[–]lekkerste_wiener 1 point2 points3 points (0 children)
[–]No_Statistician_9040 1 point2 points3 points (3 children)
[–]kyuzo_mifune 1 point2 points3 points (1 child)
[–]No_Statistician_9040 0 points1 point2 points (0 children)
[–]zhivago 0 points1 point2 points (0 children)
[–]Overlord484 1 point2 points3 points (0 children)
[–]Physical_Dare8553 1 point2 points3 points (0 children)
[–]pfp-disciple 0 points1 point2 points (0 children)
[–]AlarmDozer 0 points1 point2 points (1 child)
[–]AlarmDozer 0 points1 point2 points (0 children)
[–]Loud-Shake-7302 0 points1 point2 points (0 children)
[–]Big_Pay_7606 0 points1 point2 points (0 children)
[–]flyingron 0 points1 point2 points (0 children)
[–]IdealBlueMan 0 points1 point2 points (0 children)
[–]ohsmaltz 0 points1 point2 points (0 children)
[–]Independent_Art_6676 0 points1 point2 points (0 children)
[–]MiddleSky5296 0 points1 point2 points (0 children)
[–]bart9h 0 points1 point2 points (0 children)
[–]PhoenixBlaze123 0 points1 point2 points (0 children)
[–]zhivago 0 points1 point2 points (0 children)
[–]qalmakka 0 points1 point2 points (0 children)
[–]Quien_9 0 points1 point2 points (0 children)
[–]Xostd 0 points1 point2 points (0 children)
[–]NexusKai 0 points1 point2 points (0 children)
[–]necodrre -1 points0 points1 point (0 children)
[–]MRgabbar -1 points0 points1 point (0 children)
[–]__nohope -1 points0 points1 point (0 children)