-
C++ vs Rust Reference & Dereference 코딩 비교❤️코딩Coding/한글Rust강의★내가★공부하려고만듬 2022. 5. 20. 15:35728x90
rust cpp reference dereference training #rust #reference #dereference
https://youtu.be/zaOXxYSm6hk
c++#include <iostream> using namespace std; int main () { int number1 = 10; int *pointer1 = &number1; double number = 23.4; double *pointer2 = &number2; cout << "Number1 : " << number1 << "(size : " << sizeof(number1) << " ) " << endl; cout << "Pointer1 : " << pointer1 << "(size : " << sizeof(pointer1) << " ) " << endl; cout << "Number2 : " << number2 << "(size : " << sizeof(number2) << " ) " << endl; cout << "Pointer2 : " << pointer2 << "(size : " << sizeof(pointer2) << " ) " << endl; return 0; }
Rustfn main() { let mut number1:i32 = 10; let number1_ref = &mut number1; let number1_ref_ptr_add = number1_ref.clone(); *number1_ref = 9; println!("Rust \n Refenrence & Deference & pointer Address"); println!("Number1 : {} \n size of(number1) :{} \n", number1, std::mem::size_of_val(&number1)); println!("Number1 pointer address : {:p}", &number1_ref_ptr_add); let mut float64_02:f64 = 23.456; let float64_02_ref = &mut float64_02; let float64_02_ref_ptr_add = float64_02_ref.clone(); *float64_02_ref = 45.678; println!("Rust \n Refenrence & Deference & pointer Address"); println!("float64_02 : {} \n size of(float64_02) :{} \n", float64_02, std::mem::size_of_val(&float64_02)); println!("Float64_02 pointer address : {:p}", float64_02_ref_ptr_add); }
f64
println!("Float64_02 pointer address : {:p}", float64_02_ref_ptr_add);
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `Pointer` is not implemented for `f64`
|
note: required by a bound in `ArgumentV1::<'a>::new_pointer`
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
이 오류 해결 해야함
해결책
https://doc.rust-lang.org/std/primitive.f64.html
최종fn main() { let mut number1:i32 = 10; let number1_ref = &mut number1; let number1_ref_ptr_add = number1_ref.clone(); *number1_ref = 9; println!("Rust \n i32 \n Refenrence & Deference & pointer Address"); println!("Number1 : {} \n size of(number1) : {}", number1, std::mem::size_of_val(&number1)); println!("Number1 pointer address : {:p}", &number1_ref_ptr_add); let mut float64_02:f64 = 23.456; let float64_02_ref = &mut float64_02; let float64_02_ref_ptr_add = float64_02_ref.clone(); *float64_02_ref = 45.678; let f64_add = float64_02_ref_ptr_add.to_bits(); println!("\n f64 \n Refenrence & Deference & pointer Address"); println!("float64_02 : {} \n size of(float64_02) : {}", float64_02, std::mem::size_of_val(&float64_02)); println!("Float64_02 pointer address : {:p}", &f64_add); } }
easy rust 018 -
mutable references
https://youtu.be/1ZOf5MD-L3E
easy_rust 043:
Dereferencing , . operator
https://youtu.be/znCUAqyfbe4
rust : 117- Deref trait
https://youtu.be/tFC8ZWvMDOE
rust 변수 메모리 주소 출력하는 방법
https://stackoverflow.com/questions/46683073/why-is-the-memory-address-printed-with-p-much-bigger-than-my-ram-specs
rust Deref
https://stackoverflow.com/questions/27938260/what-happens-when-i-write-to-a-random-memory-address
Go에서 pointer개념
https://developpaper.com/go-advanced-feature-12-pointer-explanation-under-what-circumstances-should-pointers-be-used/
출처 : 노마드 코더 Nomad Coders
https://nomadcoders.co/javascript-for-beginners
[JavaScript]NaN은 Not a Number(숫자가 아님)이라는 뜻
https://economiceco.tistory.com/10947
반응형'코딩Coding > 한글Rust강의★내가★공부하려고만듬' 카테고리의 다른 글
러스트에도 파이썬 넘파이와 비슷한 라이브러리가 있다?rust vs python numpy #rust #ndarray #numpy (0) 2022.05.23 Rust Error❤️Handling 외우자❤️공식 & anyhow_easyrust만세 (0) 2022.05.23 한글Rust러스트❤️015_Option_part3_Implementing_Vec_Rustonomicon (0) 2022.05.22 Rust❤️)enum, struct등등 용량 계산하기 (0) 2022.05.22 VSCode활용법--diff❤️2개 코드 비교해서 보기_틀린 곳 찾기 #vscode #diff (0) 2022.05.19 Rust🧑💻Programming Full Course Tutorials 💻❤️ (0) 2022.05.19 rust turtle❤️검색 하다가 알게 됨 코딩해 볼 예정 (0) 2022.05.19 러스트❤️vs C++벡터연습_rust cpp vector training LunarVim_Install&Settings&LspInstall (0) 2022.05.18