Printing in C

Printing in C

In C for printing purpose, We Use A Function Called printf( ).

A function is a small program used to perform a specific task. The function receives some input known as an argument and produces some output called return value. Functions are always suffixed with parenthesis ( ).

Syntax of printf( )

printf("Control String",[List or Variable]);

Note: Control string is a sequence of characters that you want to print. ([ ]) square brackets around the list or variable represent that it is optimal.

Example Of printf( )

printf("Hello"); //prints Hello
int a = 5,b = 6;
printf("%d %d",a,b); //prints 5 6
printf("Total = %d",a+b); // Total = 11

The first program, Say Hello World in C programming

/*program to print the "Hello world"*/
int main() {
     printf("Hello World");
     return 0;  
Program Explanation
  1. First list the comment is specified for the name and purpose of the program Statement printf("hello world"); it is used to print the msg "hello world" on the output screen.
  2. Because the program is the collection of the statement which performs a specific task and all the statement are collectively enclose in main() function.
  3. main() is the starting point of the program which is called by the running environment generally OS.
  4. The pair of curly braces {} is used to combine the statement in a group.
Statement terminator
  1. In the previous program, you observe that every line ends with a semicolon(;). The semicolon is known as the end of the statement.
  2. Whenever one statement ends we have to put a semicolon(;).
  3. If we write the program in a single line by separating each statement with a semicolon, the compiler doesn't matter because of compiler treat semicolon(;) at end of a line but this way of writing makes the program very difficult to read and understand. So for efficiency, we have to write the program as clear as possible because the white space and blank lines have no effect on the output.
  4. Observe carefully that the main() function doesn't end with a semicolon because of the main end at the closing curly braces.

Printing in C | Video Tutorial in C