Basically C and C++ have no input and output staments but the ANSI standard defined few which are below
- The printf ( ) function
It is very usefull fucntion,It give us the output like
#include<stdio.h>
main()
{
int x,y;
float e,r;
x = 15;
y = a / 2;
printf("%d\n",y);
printf("%3d\n",y);
printf("%03d\n",y);
e = 15.3;
r = c / 3;
printf("%3.2f\n",r);
}
output given below
7
7
007
5.10
2.The clrser ( ) function.
It basically clear the textmode window and palce the cursor in the left side corner like
#include<stdio.h>
#include <conio.h>
void main()
{
int a;
clrscr();
for( a = 0; a < 10; a++)
printf("clrscr function test\n");
printf("\n\nPress any key to clear screen");
getch();
clrscr();
printf("The screen has been cleared!");
getch();
It give the output like
when press any key then give output like
3.The cout, output stream.
It is a standard output stream use print the screen like
using namespace a;
cout<<setw(10)<<"ten"<<"hello"<<"hello";
the output is
ten hellohello
4.The putch ( ) & putchar ( ) Character output Function
Both are use to print the single charactor value like
putch(char variable);
int main()
{
char a;
printf("enter value of a ");
a =getch();
printf("\n value of a is \t ");
putch(a);
}
Input enter value of a b
no need to hit enter
Output value of ch is b
5.The puts ( ) String output Function.
Is basically use to print the string its standard formate are like
#include <stdio.h>
int puts(const char *string);
int main(void)
{
if ( puts("Hello World") == EOF )
printf( "Error in puts\n" );
}
Output
Hello World example it work like
#include <stdio.h>
int main(void)
{
if ( puts("Hello friend") == EOF )
printf( "Error in puts\n" );
}
Output
Hello friend
- The scanf ( ) function
is a input fucntion use for to input any thing in programmning laguage like
#include<stdio.h>
int main()
{
int myvariable;
printf("Enter a number:");
scanf("%d",&myvariable);
printf("%d",myvariable);
return 0;
}
Out put of this porgrame suppose if we enterd 10 then output look like as
Enter a number 10
2.The gets ( ) function.
Is also a input fucntion work same like scanf but The gets ( ) function is dngerouse like a devile tool that creating buffers in overfollow like
In scanf we entetr name like Bashir
IN getch we enter name like Bashir Ahmad
3.The getchar ( ), getch ( ) , and getch ( ) functions.
Is a input fucntio getchar use for characters to get from consols and echoes the screen,is a library funciotn and decleared like int getchar(void);
while getch() also use to get character from console but it don,t not echoes the screen,is also a library fucntion and decleared like in getch(void);
4.Input using cin
it is absically use in C++ for input console applications to get the char and string from the user.like
char bashir;
cin >> bashir;