Skip to content

Instantly share code, notes, and snippets.

@oscarryz
Last active September 13, 2022 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oscarryz/f29b6a0f9bf5d9574e7ac5b4b4941896 to your computer and use it in GitHub Desktop.
Save oscarryz/f29b6a0f9bf5d9574e7ac5b4b4941896 to your computer and use it in GitHub Desktop.
Rust Memory Management Notes
#include <stdio.h>
int main(int argc, char** argv)
{
char* h = "hello"; // char* -> ['h' 'e' 'l' 'l' 'o' '\0'] length: 5
char* w = "world";
// printf("%s, %s!\n", h, w);
// char* s = "secret";
// printf("%s, %s %s!\n", h, &h[12], w);
// printf("%s, %s %s!\n", h, h+12, w);
//
// int i;
// for (i = 0 ; i < 19; i++ ) {
// printf(" %c ", h[i]);
// }
// printf("\n");
// for (i = 0 ; i < 19; i++ ) {
// printf("0x%x ", h[i]);
// }
}
#include <iostream>
#include <string>
using namespace std;
int main() {
string h = "Hello";
string w = "world";
string s = "secret";
cout << h.length() << endl;
cout << h << "," << w << "!" << endl;
cout << "[" << h[19] << "]";
return 0;
}
fn main() {
let h = String::from("Hello");
let w = String::from("world");
println!("{h}, {w}!");
// let s = String::from("secret");
// println!("s: {s}");
// let t = s;
// println!("s: {s}");
// println!("t: {t}");
// let v = thing(t);
// println!("t: {t}");
// println!("{v}");
// let x = size(&v);
// println!("{v}");
// println!("{x}");
}
// fn thing(s: String) -> String {
// let r = s.chars().rev().collect::<String>();
// r
// }
// fn size(s: &String) -> usize {
// let size = s.len();
// size
// }
// fn dangle() -> &String {
// let stuff = &String::from("new stuff");
// return stuff;
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment