String interpolation

Embeds variables into a string to build a complete sentence.

C C23

C23
#include <stdio.h>

int main(void) {
    const char *name = "Alice";
    int age = 30;
    // C has no string interpolation; sprintf formatting composes the string (equivalent to "{$name} is {$age} years old")
    char buf[64];
    snprintf(buf, sizeof(buf), "%s is %d years old", name, age);
    printf("%s", buf);
    return 0;
}
Output
Alice is 30 years old

C++ C++26

C++26
#include <iostream>
#include <string>
int main() {
    std::string name = "Alice";
    int age = 30;
    // C++17 has no built-in interpolation; compose with chained << output
    std::cout << name << " is " << age << " years old\n";
    return 0;
}
Output
Alice is 30 years old

C# v11.0.100

v11.0.100
var name = "Alice";
var age = 30;
Console.WriteLine($"{name} is {age} years old");
Output
Alice is 30 years old

Go v1.27.4

v1.27.4
package main

import "fmt"

func main() {
    name := "Alice"
    age := 30
    fmt.Printf("%s is %d years old\n", name, age)
}
Output
Alice is 30 years old

Java v27.0.1

v27.0.1
public class Main {
    public static void main(String[] args) {
        String name = "Alice";
        int age = 30;
        System.out.printf("%s is %d years old%n", name, age);
    }
}
Output
Alice is 30 years old

JavaScript v26.13.1

v26.13.1
const name = "Alice";
const age = 30;
console.log(`${name} is ${age} years old`);
Output
Alice is 30 years old

PHP v8.6.0

v8.6.0
$name = "Alice";
$age = 30;
echo "{$name} is {$age} years old";
Output
Alice is 30 years old

Python v3.15.2

v3.15.2
name = "Alice"
age = 30
print(f"{name} is {age} years old")
Output
Alice is 30 years old

Rust v1.99.1

v1.99.1
fn main() {
    let name = "Alice";
    let age = 30;
    println!("{} is {} years old", name, age);
}
Output
Alice is 30 years old

TypeScript v26.13.1

v26.13.1
const name: string = "Alice";
const age: number = 30;
console.log(`${name} is ${age} years old`);
Output
Alice is 30 years old

Language differences

C: no string interpolation — snprintf/sprintf formatting builds the string.

Go: %s/%d verbs with fmt.Printf/Sprintf.

Java: printf/String.format.

JavaScript: backtick template literals with ${}.

PHP: interpolates $var or {$var} inside double quotes; single quotes do not interpolate.

Python: f-strings (3.6+, f prefix) or .format().

Rust: {} placeholders with println!/format!.