-
-
Notifications
You must be signed in to change notification settings - Fork 9
C String Literal
IsaacShelton edited this page Mar 21, 2022
·
1 revision
C-String literals are strings surrounded with single quotes:
'Hello World'
'John'
'Welcome, Isaac Shelton.'
They are null-terminated and are of type *ubyte
. They should not be modified without first creating a copy.
import basics
func main {
firstname *ubyte = 'Isaac'
lastname *ubyte = 'Shelton'
fullname *ubyte = malloc(strlen(firstname) + 1 + strlen(lastname) + 1)
defer free(fullname)
sprintf(fullname, "%s %s", firstname, lastname)
greet(fullname)
}
func greet(fullname *ubyte) {
printf("Welcome %s!\n", fullname)
}