BEGINNING WITH C – WRITING OUTPUT DATA
Generally, we can write the output data i.e. From the computer memory to the standard output device i.e. MONITOR with the help of numerous library and non-standard functions. Thus, some of the functions for writing output data are printf(), putchar(), putch(), etc.
Firstly, we will discuss everything about the library function printf() –
1. printf() –
Basically, printf() is a function with which we can easily write all type of values i.e. numeric, character or string as OUTPUT.
The syntax for prinf() is as following –
printf(“control string”, variable 1, …….);
As, in the syntax.. The control string contains conversion specification characters and text. Especially relevant, we must enclose the control string within double quotes ( ” ” ).
Most noteworthy, we should never place the Ampersand sign [&] prior to the name of the variables. Furthermore, if there’s no conversion specification in the control string.. Then, there’s no specification of the variable names.
Now, Following are some of the examples of print() function –
EXAMPLE 1 – WRITING TEXT AS OUTPUT
printf(“WELCOME TO C PROGRAMMING”);
WELCOME TO C PROGRAMMING
Here, there’s no conversion specification in the control string. Also, there’s only text in the control string. Hence, the output is only text.
EXAMPLE 2 – DISPLAYING AN INTEGER VALUE AS OUTPUT
prinf(“ENTER THE NUMBER – “);
printf (“\nTHE NUMBER IS – %d\n”, number);
ENTER THE NUMBER – 10
THE NUMBER IS – 10
Now, in the about example.. Control string contains a conversion specification character i.e. %d. Hence, it implies that compiler will display an Integer value on the output screen. Certainly, the variable number has that integer value that the compiler will display as output.