You are on page 1of 5
Here's an eaumple of how 10 use if-else Ladder: anduino ‘Copy code int ape ~ 18; if (age = 18) printf" You are not eligible far voting”): 1 ete if (age = 18 Ad age = 60) | printf" Vou are eligible for voting”; } set priaaft"Vou are a senior cititen"}c 1 Inn thts example, the if-else ladder statement checks the value of the variable age and executes the appropriate block af code. ‘The switch case stutement abso evehunes am expression und execunes the block of code Ubu naitcbes the value of the expressicm. It works 2s filbows: sowitch (expression) { aie valuel: Ji onde to exevute when expression equals vaksel ‘break; ‘ease valu: J oode to execute when expression équels vane? ‘break; case value: onde to execute when expression equi vane’ shrek; defi: \Voode to exceute wiken none af the eases ninich the expression The Continue cutenent is meet to skip the current iteration of a loop and move om 10 the weet iteration. When a. continue statement i encountered imide-a loop, the loop skips the current iieration and proceeds. with the new iteration. Here's an example of how to use continye im a while loop: peel Copy code inti ty while (i= 10) | is i%2—o| -contimse. ! primtfi"%icd "a 1 inthis example, the while loop iterates from | to 10. Whee dhe value of fs even, the if aatement is ‘ue, and the contig statement is execute! This slopes the current iteration and proceeds with uhe next iteration. ‘The ouipan of this program would be $574 11 in semmary, break is used to terminate a loop, while cominmue is used so skip the current iteration ofa loop wad move on to the next iteration. Explain Switeh case and Ef else ladder with example ta programming tanguage, if-else ladder and swinch case are conditional statements used to make devisions based on the value of an expression. ‘The id-else ladder starement evaluates multiple conditions ina sequence and executes the block of code that matches the condition. ft works ax follows: if (ocnditices 1) | code to execute when condition! is trac (code te execute when none of the condition: are sue What is array? How to imitislice 1-0 and 2-9 arrays? Cam array indes be megative Anaray is a collection of elements of the same data type, stored in contiguous memory Jocutices, and accested using.» common same and an index om subscript Tor initialine « 1-0) amay in, you can use the following syntax: dhia_iype array namefarray sine] {inifializtiem values}; For example, to cfeate an army of integers with 4 clements and initialize it with values 1.2 3. 4, and 4. you cum use the folhowing code: int anf] = (1,203.4, 5h: Tor initialize 2 2-0) aay in dita_type aay namefow_sine{foohumn size] ~ finitialiation values}; For example, 1o create u 2-D army of integers with 2 vows and 3 columns und initiakive it with values 1.2, 34 5, and 6, you can use the following code: int arf 2913] = E23}, J, 8: Note that the initialization values ate encheed in curly beaces and separuicd by commas. You can omit the site of the army in the ininalization and the comspiler will determine the size based om the number of elements. you cam use the [olbwing syntax: In, array indices must be-non-eegative integers. Negative indices are mot allowed and will result in a ‘compilation emor or undefined behavioe at runtime. The firet element of un array has an index of, anf the last clement has an index af size-t. Explain break wed continue statement with example In © programming tanguage, the bretk and oastime statements are used to commal the fhow of etecution in léops. The break Statement is used to inumediately terminate the execution ofa loop. When a break cutensem is encountered inside a loop, the Joop is immediately terminated and the control is transferred to the ststement immediately following the boop. Here's an example of how 10 use bres in a. dor loop: for (int i= 1p b= 1a +9 fi 5} f break: 4 printfa “ic J In this example, the for loop iterates fram to LD. When the value wf iis 4, the if statement is true, and the break statement is executed This terminates the loop, and the conmol is trassferred ao the siatement immediately following the boop. The ouipat af this program would be: 123.4 Agigamenst Operators: These operwtors are used to wssign a value toa variable. Example: Equivalent toa =a+3 # Equivalent toa =a - 3 Equivalent toa =a * 3 Equivalent toa 3 a Y= 3: // Equivalent toa =a% 3 Bitwise Operators: These operators are used to perform operations on binary numbers. Exatnple: inta = $b =3, int c= a & b; J! Bitwise AND operator int d=a| b; /’ Bitwise OR operator ime =a b.! Biwise NOR operator int f=-a, // Batwise NOT operator Left shift operator ! Right shift operator ‘Condithonal Operator: This operator is used 1 evaluate a condition and return one of two values based on the result of the condition. Example: inta=3,b=3; int ax, > by Pa: by printf The maximum value is Md", max) Increment and Decrement Operators: These operators are used to increment ot decrement the value of a variable hy 1. Exatple: Increment operator an, |! Decrement operator 1. Explain different operators in C. Ans, In C programming language, operators are used to perform mathematical or logical operations on one ar more operands. Here are some of the commonly used operators im C: Arithmetic Operators: These operators are used to perform mathematical operations like addition, subtraction, multiplication, division, and modulus int g=a% b; // Modulus operator Relational Operators: These operators are used to compare two operands und eeturn 3 Boolean value truc or false. Example: inta=$.b=3; iffa > b) | printfa is greater than b"); 1 ila b && o> b) | printfi"Both conditions are true"): ! iffa > be BD) printf" is not greater thun bi); }

You might also like