Output Instruction

  §  In C, a standard output device is monitor and printf () is used to send data/message to monitor.

  §  Printf () is a predefined function.

  §  In C++, we can use cout to send data/ message to monitor.

  §  cout is a predefined object

  §  The operator << is Called the insertion or put to the operator.

Printing a Message

Printf (“Abhishek Sharma”);
cout<<” Abhishek Sharma”;

Printf (“Sum of %d and %d is %d”,a,b,c);
cout<<”Sum of”<<a<<”and”<<b<<”is”<<c;

Printf(“%d,a+b”);
cout<<a+b;


Input Instruction

  §  In C, a standard input device is keyboard and scanf () is used to receiving data from the keyboard.

  §  Scanf () is a predefined function.

  §  In C++, we can use cin to input data from the keyboard.

  §  cin is a predefined object

  §  The operator >> is Called the extraction or get to the operator.

Scanf(“%d”,&a);
cin>>a;

Scanf(“%d%d”,&a,&b);
cin>>a>>b;

Scanf(“%d%f”, &a,&c);
cin>>a>>c;

Remember that

§  ANSI standards for C++ language says explicit declaration of the function is compulsory.

§  Predefined functions are declared in the header file so that whenever you are using any predefined function in your the program, you have to include a specific header file that contains its declaration.

About iostream.h

§  We need to include the header file iostream.h, it contains the declaration for identifier cout and the operator <<. And for the identifier cin and the operator >>.

§  Header files contain the declaration of identifiers.

§  Identifiers are can be a function names, variables, objects, Macros, etc.

About endl

  §  Insertion endl into the output stream causes the screen cursor to move the beginning of the next line.

  §  endl is manipulation and it is declared in iostream.h header file.

  §  ‘\n’  character also works as it works in C.

https://abhisharmaofficial.blogspot.com/

**You reached end of lecture**