#include<iostre am.h>
#include<conio. h>
void main()
{
clrscr();
char name[5];
cout<<"Enter your name";
cin>>name;
cout<<"Your name is"<<name;
getch();
}
In the above program the size of the array of the variable name is 5. which means the variable cant store more than 5 characters.
which also means
If I give the string "LINISH"
It should only print LINIS
But while the program is running, Even if I type a 10 characters string, It is getting printed Completely..why ???
Kindly be kind enough to go through the below program also:
#include<iostre am.h>
#include<conio. h>
void main()
{
clrscr();
char name[5];
char game[5]
cout<<"Enter your name";
cin>>name;
cout<<"Enter your favorite game";
cin>>game;
cout<<name"Love s"<<game;
getch();
}
In this program when I input a string for the variable name,It is getting printed completely, irrespective how many characters are there in the string.
But If the string (which is input to the second variable that is game )holds more than 5 characters. the input of the first variable(name) is getting disturbed..why? ?/
look at the below cited output to be more clear about my doubts.
OUTPUT NO:1
Enter your name:LINISHFRAN CIS (Note that the input holds more than five chars)
Enter your game:GOLF(input is less than five chars)
LINISHFRANCIS loves GOLF(Two inputs are getting printed comopletely)
OUTPUT NO:
Enter your name:LINISHFRAN CIS (Note that the input holds more than five chars)
Enter your game:FOOTBALL(i nput is more than five chars)
ALL loves FOOTBALL [Note that "ALL" is the last three letters of FOOTBALL
I am using TurboC++ for windows 7
Thanks in advance
#include<conio. h>
void main()
{
clrscr();
char name[5];
cout<<"Enter your name";
cin>>name;
cout<<"Your name is"<<name;
getch();
}
In the above program the size of the array of the variable name is 5. which means the variable cant store more than 5 characters.
which also means
If I give the string "LINISH"
It should only print LINIS
But while the program is running, Even if I type a 10 characters string, It is getting printed Completely..why ???
Kindly be kind enough to go through the below program also:
#include<iostre am.h>
#include<conio. h>
void main()
{
clrscr();
char name[5];
char game[5]
cout<<"Enter your name";
cin>>name;
cout<<"Enter your favorite game";
cin>>game;
cout<<name"Love s"<<game;
getch();
}
In this program when I input a string for the variable name,It is getting printed completely, irrespective how many characters are there in the string.
But If the string (which is input to the second variable that is game )holds more than 5 characters. the input of the first variable(name) is getting disturbed..why? ?/
look at the below cited output to be more clear about my doubts.
OUTPUT NO:1
Enter your name:LINISHFRAN CIS (Note that the input holds more than five chars)
Enter your game:GOLF(input is less than five chars)
LINISHFRANCIS loves GOLF(Two inputs are getting printed comopletely)
OUTPUT NO:
Enter your name:LINISHFRAN CIS (Note that the input holds more than five chars)
Enter your game:FOOTBALL(i nput is more than five chars)
ALL loves FOOTBALL [Note that "ALL" is the last three letters of FOOTBALL
I am using TurboC++ for windows 7
Thanks in advance
Comment