Compiler Directive

Compiler Directive

Complier directives such as define and include are special instructions to the compiler to help it to compile a program. They do not end with semicolon. The sign # of compiler directives must appear in the first column of the line. When the braces are used to group statements, make sure that the opening brace has a corresponding closing brace. To read data from the input device input statements are used and to print the processed data onto the output device output statements are used. These input/output (I/O) statements can be formatted or unformatted. In unformatted I/O statements no specification of data types and the manner in which they are read in or written out is mentioned. But, Formatted I/O statements specify what type of data is being input or displayed and in what way it should be. scanf() and print() are the two in-built functions use to read and print the data. They are used for all types of data like int ,char , float, double , etc. In general, it is not possible to read multi-word string with scanf() function. Using escape sequences, we can format the output as per our requirements.
 
Data type is a set of values along with set of permissible operations. Simple data types consists of integers (short, int, long), real number (float, double) and characters (char). Every data item to be used in program needs to be declared /initialized. The backslash (\) character constant performs a specific task. They begin with a backslash (\). Both the backslash and an associated character are enclosed within single quotes.
 

 
There are four data types’ modifiers like signed, unsigned, short, long. These are used to provide the accuracy and precision to the integer and character type data. Note: %* C specification is used to read the new line (\n), which is obtained by pressing the enter key and enter key is used to enter the character to reach at the new line.

Note: %* C specification is used to read the new line (\n), which is obtained by pressing the enter key and enter key is used to enter the character to reach at the new line.



C operators are basically classified into unary, binary and ternary operators. There are five unary operators, four types of binary operators and one ternary operator. Where unary, !, ++, — and – are binary operators. The +,-,*, / are basic arithmetic operators. Modulus operator is another arithmetic operator which results in the remainder after an integer division. The <, <=,>, =>, = =, ! = are relational operators. These are used to define the relation between constants and variables. C language supports variety of assignment statements. There is precedence of operators that determines the evaluation of expressions.



We have seen in this chapter, there are three types of situations that demand the change in the flow of the control. These are : 1) Skipping some segments of the programs or going back to execute the same segment again. 2) Executing one segment out of two or more segments depending on the outcome of the some condition. 3) Executing a segment repeatedly either for a given number of times or till some conditions are met. For these situations, C has four types of statements: declaration statement, inputoutput statements, arithmetic, logical statements and control statements. The control statement defines the order of execution of the program statements. There are three types of control statements: (i) conditional, (ii) looping and (iii) unconditional control statements. The four basic conditional control statements are if, if-else, if-else-if and switch statement. These are called selective or decision marking control statements. The goto is unconditional control statement which transfer the control to the specified statement in a program.



In the above program the If statement checks whether the given number is less than 0 or not. If it is less than zero then the number is negative, therefore the condition becomes true then the statement, “the number is negative” is executed. If the number is not less than zero, the If else construct skips the first statement and prints the second statement declaring that “the number is positive”. Looping is also called an iterative or repetitive control mechanism, where int set of statements are repeatedly executed either for a fixed number of times or as long as a certain logical condition is true. The while, do-while and for loop statements are the three powerful loop control structures available in C. The while statement is a pre-test loop statement (it is executed if only the expression is true) and the do-while is a post-test loop statement (it is executed at least once. Then the expression evaluated for repeating the loop). The “for” loop is used when the user knows the number of iteration to be made. Sometimes, it becomes desirable to exit a loop or skip a part of the loop in an iterative process. To do so, the break and continue statements are used.

 

Comments

Popular posts from this blog

Array