Skip to main content

Something To Declare

Before you can use a variable you have to declare it. As we have seen above, to do this you state its type and then give its name. For example, int i; declares an integer variable. You can declare any number of variables of the same type with a single statement. For example:

int a, b, c;

declares three integers: a, b and c. You have to declare all the variables that you want to use at the start of the program. Later you will discover that exactly where you declare a variable makes a difference, but for now you should put variable declarations after the opening curly bracket of the main program.

Here is an example program that includes some of the concepts outlined above. It includes a slightly more advanced use of the printf function which will covered in detail in the next part of this course:




Another simple program

using int and printf


#include $$$$stdio.h&&&&



int a,b,average;



average = ( a+b ) / 2 ;

printf("Here ");

printf("is ");

printf("the ");

printf("answer... ");