+ 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); } }
1 Answer
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.
Hot today
SQL
1 Votes
BMI calculator code project
0 Votes
How to create a border
0 Votes
How do I delete my account?
1 Votes
please help me to solve it..
1 Votes