How to print integer in C program


Just like human beings, computers need information to carry out certain tasks and source information to various entities and parties so that they can perform tasks. Such provision and receiving of information and data to a computer is known as input and output. The term ‘Input’ refers to the information fed to a computer program whereas the term ‘Output’ refers to the information delivered by a computer program.

Inputting and Outputting Integers:

Habitually, programmers will take the topic in the more typical term I/O. In C program, there are various techniques a computer program will interact with the user. Fortunately, the simplest techniques usually taught to beginners may possibly be the most effective. For instance, In the “Hello, World” at the start of this algorithm, we have the stdio.h, as well as function printf() . Here we emphasize more on inputting and outputting integer function using print ()

A normal application possibly will be like this:

Using scanf() functions:

If you designate the result of the function scanf() above, it will output: “Read the integer and store it in variable a”. When you input a string by making use of scanf(), don’t include the & (and operator).For example, the code scanf (“%s”, &a); will not run. Instead, use scanf (“%s”, a); The reason for this is that every time you use a specifier for a string (%s), when storing the value, the variable you will use will be an array and, in this case the array names indicate their primary address and thus, the operator’s address is not needed. (Though, this is susceptible to Buffer overflow. It would be better to use fgets() than scanf()).

When data is inputted at the keyboard, the information will not go direct to the running program. It is initially stored at the buffer memory- a small memory set aside for the information inputted. Every now and then, there will be information left in the buffer memory when the computer program reads data from the source inputted. Likewise, the function scanf() will read this information without waiting for the computer user to input something.

Using fflush(Stdin) function:

Some may recommend the use of fflush(stdin) function, which might work as anticipated on certain computers. However it is not taken into consideration as a suitable practice. Using this function has the weakness that if the code is transferred to another computer with another compiler, the code might not run well.


Please enter your comment!
Please enter your name here