This statement is also a conditional statement. It starts with keyword ‘if’ followed by an expression followed by “ first statement” and “ second statement” is given after ‘else’ clause.
Format:if(expression)statement1;elsestatement2;
It is used whenever any condition is to be implemented by the user it means some conditions like:1. If the price of the item is more than 5000 then discount is 10%.2. If the students marks are greater than 60% then he should be in 1st division.
/* Program to enter two values and perform addition and multiplication operation*/
#include<iostream.h>
#include<conio.h>
main()
{
int n1,n2,sum,mul;
cout<<"\n Enter any two numbers";
cin>>n1>>n2;
sum=n1+n2;
mul=n1*n2;
cout<<"\n Sum of two numbers is "<<sum;
cout<<"\n Multiplication of two numbers is "<<mul;
getch();
}
A file is a place on the disk where the group of related data are stored. The first function is to be performed when we are accessing the files is to open a file. Opening a file establishes a link between the program and the operating system about which file we want to access for what purpose. We provide the operating system to which file we want to access and for what purpose. For accessing a file we just have to name the file and plan whether we want o read data from the file or write data onto the file. The syntax for opening is:
FILE *fp;
inbuilt structure
fp= fopen( “file name”, “mode”);
Union is that data structure which is also user defined data type but to define a union keyword union is used instead of struct.
Structure is the user defined data type which can store heterogeneous data i.e. data of different types. It means in structure member with all possible data type can be used and there is no restriction that elements of the structure are stored at adjacent memory locations. Structure is declared with key word struct followed by its name and then by block.
Pointer is that variable which stores the memory address of another variable. It means pointer is itself a variable which stores hex-decimal address of the location.