I am confused after the following C++ code executed:
#include <iostream>
using namespace std;
int main()
{
char name[0];
int roll;
cout << "Enter your name: ";
cin.get(name, 30);
cout << "Enter roll no.: ";
cin >> roll;
cout << "You have entered:" << '\n';
cout << "Name: " << name << '\n' << "Roll No. " << roll << '\n';
return 0;
}
As you see, it simply takes input and print it. But the problem is, how cin is supposed to read all the characters i have entered if the value of array is 0!!!
The output is as follows:
Enter your name: Bharat Singh Chauhan
Enter roll no.: 12345
You have entered:
Name: Bharat Singh Chauhan
Roll No. 12345
Sorry if the question is asked before ;)