Computer Science, asked by pompeytamang, 9 months ago

weite about control statement
and operatores​

Answers

Answered by renukawangi28
1

Answer:

Control statements enable us to specify the flow of program control; ie, the order in which the instructions in a program must be executed. They make it possible to make decisions, to perform tasks repeatedly or to jump from one section of code to another.

hope it will help u

Answered by jmakima55
1

Answer:

3. Operators and control statements

3.1. Introduction

C provides various operators e.g. algebraic and boolean operators etc., which can be used to perform different mathematical operations. Further, various control structure of C can be used to perform these tasks repetitively or under suitable conditions. In this chapter, such operators and control structures are used to perform operations on various data-types.

3.2. Operators

Operators are the symbols which are used to perform certain operations on the data e.g. addition, subtraction and comparison etc. There are various types of operators in C, which are shown in this section; also, most of these operators are used with decision statements, therefore usage of these operators are shown in Section 3.3.

3.2.1. Arithmetic operators

Table 3.1 shows the list of arithmetic operators in C. These operations are used to perform various mathematical operations on ‘integer’, ‘float’ and ‘double’ data types. Functions of all the operators are straightforward except for ‘++’ and ‘–’, which are used to increment or decrement the value of the variable by ‘1’ respectively. These operators can be used as ‘i++ or i–’ and ‘++i or –i’. The ‘++i’ operation indicates that ‘increase the value of by ‘1’ and then use that value; whereas ‘i++’ indicates that ‘use the value of i first’ and then increment it by 1. These two operations are shown in Listing 3.1.

Table 3.1 Arithmetic Operators

Operator Description

+ Addition

- Subtraction

* Multiplication

/ Division

% Modulus (remainder) ( e.g. 3%2 = 1)

++ “Increment (e.g. if a = 1, then a++ = 2)”

– “Decrement (e.g. if a = 1, then a– = 0)”

+= -= *= /= short notation (e.g.’a += 3’ indicates ‘a = a+3’

Explanation Listing 3.1

In the listing, the variable ‘i’ is initialized as ‘1’ at Line 7, and printed at Line 9. Next, ‘i++’ operation is printed at Line 12; note that, first ‘1’ is printed by this line; and then the value is increased. This increase in value is verified by print ‘i’ again at Line 13, where the result is 2. Next, ‘++i’ operation is used at Line 16, where the value is increase first and then printed, therefore the result is ‘3’. Finally, to check the value stored in ‘i’, it is printed again at Line 17.

Listing 3.1 Difference in ‘i++’ and ‘++i’

// incrementEx.c

#include <stdio.h>

int main(void)

{

   int i = 1;  

   printf("i = %d\n\n", i);  // 1

   // print first, then increment

   printf("i++ = %d (i.e. access first and then increment): \n", i++); // 1

   printf("i = %d\n\n", i); // 2 (i.e. i is incremented by above statement)

   // increment first, then print

   printf("++i = %d (i.e. increment first and then access):\n", ++i); // 3

   printf("i = %d\n", i); // 3

   return 0;

}

/* Outputs

i = 1

i++ = 1 (i.e. access first and then increment):

i = 2

++i = 3 (i.e. increment first and then access):

i = 3

*/

Similar questions