Skip to content

C String Literal

IsaacShelton edited this page Mar 21, 2022 · 1 revision

C-String Literal

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.

Usage Example

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)
}
Clone this wiki locally