Anonymous asked in Computers & InternetProgramming & Design · 1 month ago

programming c++?

 vector<int> lastOccurance(256, -1);

what does it mean for the above code? can it be interpreted without using vector? 

thank you.

2 Answers

  • 1 month ago
    Favourite answer

    That declares a variable named "lastOccurrance" (should be "lastOccurrence" btw) to be a int vector.  It's initialized to contain 256 entries with each of them set to -1.

    You can't declare or create a std::vector object without using the template from the <vector> header, if that's what you meant by "without using vector". 

    I don't know of another standard data type that will let you initialize all elements to a specific nonzero value without typing them all out. Coding that as a C-style int[] array, would require:

        int lastOccurrence[256] = {-1, -1, -1, [...and so on], -1, -1};

    ...counting carefully so that there are exactly 256 -1 values in the initializer.

  • EddieJ
    Lv 7
    1 month ago

    C++ is NOT an interpreted language, but you can manually interpret the code without using vector if the lateral components are rearranged to form an inverted rhomboid.

    Thank you for your great question.  It has been filed in section 14.

Still have questions? Get answers by asking now.