boshlashdan keyin qator elementlarini qanday o'zgartirish mumkin

juda noob savol, oldindan uzr so'rayman.

X menda e'lon qilingan va boshlanadigan X qatori bor. Bu qatordan keyinchalik X ning yangi qiymatlarni qabul qilish kodini ishlataman.

double X[2] = { 0.85, 0.15 };
//some code using X[]

X = { 0.84, 0.16 }; //--> this gives "error: assigning to an array from an initializer list"
//more code using X[]

X[] = { 0.84, 0.16 }; //--> this gives "error: expected primary-expression before ‘]’ token"
//more code using X[]

Buning qanday usullari to'g'ri?

0
Qanday qilib X [0] = 1 va X [1] = 2 ?
qo'shib qo'ydi muallif The Quantum Physicist, manba

6 javoblar

Initializer ro'yxatlari faqat ishga tushirish vaqtida ishlatilishi mumkin.

You can use any one of the below array to init an array with name X

double X[ ] = { 0.85, 0.15 };//initialize array X with 2 values 

double X[2] = { 0.85, 0.15 };//initialize array X with 2 values with size

Agar siz yuqorida aytib o'tilgan narsani e'lon qilishni xohlasangiz, buni shunday qilishingiz mumkin.

std::array X;
X = {0.64,0.16};
0
qo'shib qo'ydi

Initializer ro'yxatlari faqat ishga tushirish vaqtida ishlatilishi mumkin.

You can use any one of the below array to init an array with name X

double X[ ] = { 0.85, 0.15 };//initialize array X with 2 values 

double X[2] = { 0.85, 0.15 };//initialize array X with 2 values with size

Agar siz yuqorida aytib o'tilgan narsani e'lon qilishni xohlasangiz, buni shunday qilishingiz mumkin.

std::array X;
X = {0.64,0.16};
0
qo'shib qo'ydi

Initializer ro'yxatlari faqat ishga tushirish vaqtida ishlatilishi mumkin.

You can use any one of the below array to init an array with name X

double X[ ] = { 0.85, 0.15 };//initialize array X with 2 values 

double X[2] = { 0.85, 0.15 };//initialize array X with 2 values with size

Agar siz yuqorida aytib o'tilgan narsani e'lon qilishni xohlasangiz, buni shunday qilishingiz mumkin.

std::array X;
X = {0.64,0.16};
0
qo'shib qo'ydi

Agar qatorga yangi qiymatni belgilash mumkin bo'lmasa, elementlarni alohida-alohida belgilashingiz kerak.

X[0] = 0.84;
X[1] = 0.16;
0
qo'shib qo'ydi
Rahmat, men buni bilmayman.
qo'shib qo'ydi muallif WOT, manba

It's not possible, but you can use std::array. Since X will be an object, your notation will be valid. Well... almost. You'll have to write it like X = {{0.84, 0.16}}; (one more pair of braces).

0
qo'shib qo'ydi

It's not possible, but you can use std::array. Since X will be an object, your notation will be valid. Well... almost. You'll have to write it like X = {{0.84, 0.16}}; (one more pair of braces).

0
qo'shib qo'ydi