Input and output operators in C (5th Day)
We can read any value using this function.
Here the compiler accept a value (integer type) from the keyboard and it is saved in the address of ‘a’. Here ‘%d’ indicates that the value is integer data type. To read other data types refer the following:
%d reads Integer data type
%f reads Floating point data type
%c reads Single character
%s reads String value
%o reads Octal integer
%x reads Hexadecimal integer
Used to display an output data in standard output device.
Above statement displays i-St@r Electronics on the monitor
printf(“%d”,a); It displays the value of variable ‘a’ in the monitor.
Decision making and branching in C program: if, else, goto, switch statementsWe can arrange the execution sequence of a program in different ways using decision making and branching statements. These instructions are also called as control statements.
Simple if-else statements‘if-else’ statements are very powerful and effective tool for decision making in C. In this situation, program codes are divided in to two sections and we are selecting one part using ‘if’ statement. ‘else’ part is optional so we can neglect it if not needed.
Here if the expression is true, the statement1 will execute and if it is false, statement2 will execute.
else-if ladder statementsSimple ‘if-else’ statements are used to select a part of codes from two sections. But ‘else if’ ladder is used to make decisions when there are many conditions.
Here the compiler makes decision from 4 conditions.
goto statementIt is used in unconditional branching. The syntax of goto statement is given below:
Here the Statement 1 to n will not be executed, before the execution, program sequence branched to Label.
switch statementThis statement is used for multiple branching. Here the branching takes place according to a valid expression.