C language : Ch1 : 3

Compare C with C++: C++ is evolved from C programming, let us take a look at the simple C architecture.

  • Objectives :
    • Function: printf() of <stdio.h> header files. It is a function which formats, converts and prints arguments as a standard output.
    • Introducing cout object of <iostream>  library of C++
    • C/C++ must have, "int main()" function, and you can call other function from the statement or coding block that resides within the curly {   } braces. Here we used a function called "printf()" of "stdio.h" library, from the main function to display a line of characters.
    • In C++ programming, "scanf()" or "printf()"of "stdio.h" header files, were replaced by a pair of objects namely "cin" and "cout" of "iostream" header file, for input and output operations.
  • File Name : Only_C1.c
  • Input and output stream in  C and C++
     
 

Step: 1 Create a source file. Select “New” submenu in the File menu, and then select “C Source file” as shown in the screen-shot illustration, below.

Step: 2 Edit and save Source file: In C programming language the function "printf()" carries out the output operation.

If you try to use “cout”, which is an object belongs “iostream” library of C++ language; you would get an error as shown below.

Step: 3 Runtime Views: C language does not support object oriented programming. Therefore, a C compiler will not compile the source code containing the object "cout" of iostream of C++ language . However you can use both "printf()" and "cout" with C++/<iostream> header file.

Step 4: Brief Discussion:

A computer is a machine which can take instructions (input) , and performs computations based on those instructions (output). The first line, "#include<stdio.h>" , contains all the instructions needed for standard input and output operations. The function, "printf()", supports formatted as well as free-format write statements. The line, printf("\n %s","Hello");, is an example of using formatted statement that prints a string.

 

C/C++ must have, "int main()" function, and you can call other function from the statement or coding block that resides with {   } braces. Here we used one function called "printf()" of "stdio.h" library. In C++ programming,  "scanf()" or "printf()"of  "stdio.h" header files, were replaced by a pair of objects namely "cin" and "cout" of "iostream" header file, for input and output operations.