为什么以下程序将"0x2ffee4"打印到控制台?
#include <string>
#include <iostream>
using namespace std;
int main() {
string city1[] = "toronto";
cout << city1;
return 0;
}
Run Code Online (Sandbox Code Playgroud) 无符号int只能容纳32位数据.当我为它分配一个比它能容纳的值更大的值时,为什么编译器不会给出错误?
我尝试了其他各种值,但仍然没有错误.
int main()
{
unsigned int mem = 0x89678456543454345934;
cout << mem;
return 0;
}
Run Code Online (Sandbox Code Playgroud) main中的for循环假设pop_back值只打印数组中值的一半.但是,当我写(i <=用户)时,它会打印所有值.
MyVector.h
template<class T>
T MyVector<T>::Pop_back( ){
return elements_ptr[--vectorSize];
}
Run Code Online (Sandbox Code Playgroud)
main.cpp中
int main()
{
MyVector<int> v1;
int user = 500;
for(int i= 1; i <= user; i++){
v1.Push_back(i);
}
cout << v1.size() << endl; // outputs 500
for (int j = 0; j < v1.size(); j++){
cout << v1.Pop_back() << " ";
if( j % 20 ==0 ){
cout << endl;
}
}
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我的程序计算字符串中每个数字从0到9的出现次数.在我看来,我已经完成了所有事情,但问题仍然存在.
int main(){
string word = "23456745";
int* ReturnArray = count(word);
for(int i =0; i < 10; i++){
cout << i << ": " << ReturnArray[i] << " \n";
}
delete [] ReturnArray;
return 0;
}
int* count(const string& s){
int length = s.length();
int* array = new int(10);
int counter =0;
for(int j = 0 ; j < 10 ; j++) {
for(int i = 0 ; i < length ; i++) {
char character = s[i];
int value …Run Code Online (Sandbox Code Playgroud)