#Meta-Wlp: #Macro: TITLE wlp: Learn C (III) p. 6
In this code, t is the reference to the character, *t is the character itself. To move to the next character, we write:
t += 1 ;When t references the last character, *t is something which evaluates to false when used as a logical expression, hence the while loop terminates.
Will this, slightly different program, also work,
#include<stdio.h> int main(){ char * s, t ; /* declare s and t as references to character */ s = "I am a string - " ; t = "but what am I?" ; printf(s) ; while ( *t ) { printf ("%c",*t) ; t += 1 ; } printf("\n") ; }#Shuffle: none $PAGE$-A $PAGE$-B Return to Learn C Table of Contents #: No, it is wrong. #: Yes, it is the same. #: