IO statements and expressions

Intro Text

Hi all, We’ll see some basic of C and then I will explain you the step by step process to full fill the given requirement with code snippet i.e programs using io statements and expressions. Finally we will compile all the snippets together to a complete program that can used in your own compiler. All the programs given in this website is tested. We use Turbo C++ in windows 10 for this lab programs.

Lets get started with our requirement. It states that we need to create a program I/O statements and expressions. Before get into that we will discuss about the basic structure of C program .The C programs requires some basic file which will act as a header. Header files has extension .h . Header file has the C programs function declaration and its macro definition. It will be used to define variable, functions, constants in C.We will include header file using the following snippets


#‘ is defined as¬†Preprocessors in C. we will include header file using “#include< >“. stdio.h is described as Standard Input Output . It deals with printf(), scanf(), etc,. conio.h is described as Console Input Output. It’s for windows system to utilize some function like getch(), clrscr(), etc,. conio.h is not required in linux based compilers or cmd line based compilers. Following is the basic structure of C program.

 #include<conio.h> //not required for linux compilers
 int main(){
    //logic goes here!!!
    return 0;

C program always starts from main() . int represent the return type of the program. we can use other data types as a return type for a program. this is only concern for the big project. we can use int / void. as we all know void means it returns nothing. if we represent return type as integer ,then we need to return a numerical value. we will usually use return 0.

Okay, lets come to our requirement , we need to use I/O statement and expressions.we will go from basics. lets start with output statement. the following snippet is used to display output in statement in C programming

 printf("Output Statement Goes Here!!!");

and the following code will be used to display a stored variable value

 char *name="madesh"; //variable initialization
 int age=21;
 printf("Age of %s is %d",name,age); // %s is for string , %d is for int

The following snippet will be used to get inputs from user

 int value; // variable declaration
 scanf("%d",&amp;value); //we will always use the variables address to store its value

and for expression there are many expression which can be used in a program. I used some basic mathematical operation in the program. You can give a try with some complex expressions. The following code is a working program which met our requirement (i.e) We used I/O statement to display value to user and to get value from user and use evaluated some expression in our program.


 Experiment: Programs using I/O statements and expressions
 #include<conio.h> //not required for linux compilers
 void main(){
     char name[20];
     int a=5,b=3,c;
     clrscr(); //not required for linux compilers
     printf("I/O Statements:");
     printf("\nEnter ur name:");
     printf("\nname is %s",name);
     printf("\na+b is %d",c);
     printf("\na-b is %d",c);
     printf("\na*b is %d",c);
     printf("\na/b is %d",c);
     getch(); //not required for linux compilers

If You have any queries, feedback or suggestions kindly write it to [email protected]. we will respond¬† your mail as soon as possible.Thank You !! Happie Coding !!