Skip to content
Snippets Groups Projects
Commit bc340570 authored by Stepanov Evgeniy's avatar Stepanov Evgeniy
Browse files

Add example of size_t wrong usage

parent 463182a4
No related branches found
Tags first_example
No related merge requests found
#include <iostream>
#include <cstddef>
class vint {
private:
int *data;
public:
vint(std::size_t size) {std::cout<<size<<std::endl; data = new int[size];}
int get_value(std::size_t index) { return data[index]; }
void set_value(size_t index, int value) {data[index] = value;}
};
int main(void)
{
vint a(-3);
for (uint i = 0; i < 3; ++i)
a.set_value(i, i);
for (uint i = 0; i < 3; ++i)
std::cout << a.get_value(i) << " ";
std::cout << std::endl;
return 0;
}
#include <iostream>
#include <cstddef>
#include <string>
int main(void)
{
std::string example = "This is example string";
for (size_t i = example.size() - 1; i >= 0; i--) {
std::cout << example[i] << std::endl;
}
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment