+ 1

Why is he giving the Extra-Terrestrials mission incorrectly?

#include<iostream> using namespace std; int main(){ char *a=new char; cin>>a; for(int f=15;f>=0;f--){ cout<<*(a+f); } }

5th Apr 2020, 11:27 AM
Zeynalow Azim
Zeynalow Azim - avatar
1 Antwort
0
1. You only allocated space for a single character, not for an array of them, so you also only get a single character from the input. 2. You don't know how long the string is, by using a fixed 15 characters depending on its length you might be printing garbage values or not the entire string. (3.) You didn't delete the allocated memory, but that won't make it fail. You could just use C++ strings, it's way more convenient.
5th Apr 2020, 11:32 AM
Shadow
Shadow - avatar