How to make an array without the use of square brackets?

Closed due to the fact that the essence of the issue is not clear to the participants of Kromster , Cerbo , LFC , AnT , 0xdb on March 15 at 8:48 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Unclear. Give examples, describe in more detail what you want. - Mikhail Murugov
  • And you can reformulate the question? An array is just a convenient way to access ordered data. - MBo
  • Macro via #define - nick_n_a
  • Use the pointer - avp pm

2 answers 2

Like a bicycle without wheels ... Do you explain exactly what you want?

Brackets cannot be used categorically? At all? then it is necessary through malloc .

 int a[10]; a[1] = 5; 

change to

 int*a = (int*)malloc(sizeof(int)*10); *(a+1) = 5; 

It'll do?

  • 3
    You can trigraph more. a??(10??) :) - Alexey Ten
 #include <string> #include <iterator> #include <iostream> #include <algorithm> #include <array> int main() { // конструктор ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ Π°Π³Ρ€Π΅Π³Π°Ρ‚Π½Ρ‹ΠΉ ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·Π°Ρ‚ΠΎΡ€ std::array<int, 3> a1{ {1,2,3} }; // Ρ‚Ρ€Π΅Π±ΡƒΡŽΡ‚ΡΡ Π΄Π²ΠΎΠΉΠ½Ρ‹Π΅ Ρ„ΠΈΠ³ΡƒΡ€Π½Ρ‹Π΅ скобки, std::array<int, 3> a2 = {1, 2, 3}; // Π·Π° ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ΠΌ ΠΎΠΏΠ΅Ρ€Π°Ρ†ΠΈΠΉ присваивания std::array<std::string, 2> a3 = { {std::string("a"), "b"} }; // ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°ΡŽΡ‚ΡΡ ΠΎΠ±ΠΎΠ±Ρ‰Ρ‘Π½Π½Ρ‹Π΅ Π°Π»Π³ΠΎΡ€ΠΈΡ‚ΠΌΡ‹ std::sort(a1.begin(), a1.end()); std::reverse_copy(a2.begin(), a2.end(), std::ostream_iterator<int>(std::cout, " ")); // поддСрТиваСтся ranged for Ρ†ΠΈΠΊΠ» for(auto& s: a3) std::cout << s << ' '; } 

From the manual