Assignment - 3

 

 

Please follow me for more Assignment....


1: List out Categories of Operators in c language.

A1: Categories of Operators in C Language are:

1. Arithmetic Operators.       2. Logical Operators.

3. Relational Operators        4. Assignment Operators.

5. Bitwise Operators             6. Increment / Decrement Operator.

7. Special Operators.             8. Conditional (Ternary) Operator.

 

2: What is operator? Give the name of two unary operator.

A2: Operator is used to perform or construct an expression along with operands.

Unary +, unary -, increment and decrement operator.

 

3: Write the output of the following expression:

a) 21/(int)3.5 = 7

b)45%10 - 4 + 4 = 5

c) 25 % 4 / 4 = 0

 

Please follow me for more Assignment....

 

4: Explain arithmetic operators with one example.

A4: Arithmetic operators are used to perform basic arithmetic operations on variables.

E.g sum = num1 + num2;

 

5: Explain Relational operators with example. OR List out six relational operators and give their meaning.**

A5: Relational operators are used to compare two values. They return a Boolean result, which is either true (1) or false (0).

 

1.    Equal to (==): Checks if two values are equal.

2.    Not equal to (!=): Checks if two values are not equal.

3.    Greater than (>): Checks if the left operand is greater than the right operand.

4.    Less than (<): Checks if the left operand is less than the right operand.

5.    Greater than or equal to (>=): Checks if the left operand is greater than or equal to the right operand.

6.    Less than or equal to (<=): Checks if the left operand is less than or equal to the right operand.

 

6: Select the Correct hierarchy of arithmetic and logical operation.

a. ! / + * - && ||

b. * - / && || + !

c. && || + - ! / *

d. / * + - ! && ||

 

7: List all logical operators with their meaning.***

 

A7:

1.    Logical AND (&&): Returns true if both operands are true; otherwise, it returns false.

2.    Logical OR (||): Returns true if at least one of the operands is true; it returns false only if both operands are false.

3.    Logical NOT (!): Returns true if the operand is false, and vice versa.

 

8: Describe ternary operator in C language. OR Explain conditional operators with syntax and example .OR

How we can use conditional operator in place of if else statement. ***

A8: The conditional operator (ternary operator) is a shorthand way to express a simple if-else statement. It is denoted by the ? : symbols and has the following syntax:

condition ? expression_if_true : expression_if_false;

e.g. max = num1 > num2 ? num1: num2;

 

Please follow me for more Assignment....


9: If b=10 and c=5 then what will be the values of a, b and c after the execution of following statement: a = b++ - c*2.

A9:

a = 0

b = 11

c = 5

 

10: Evaluate: c=a-- + ++b, where a=8 and b=7.

A10:

++b becomes 8.

a—after this expression becomes 7.

c = 8 + 8 = 16

 

11: Write an output for the following program segment if valid. int n1,n2; n1=81 ; n2=181; printf (“%d “ , n1 > n2 ? n1 : n2);

A11: 181

 

12: Explain increment and decrement operators with one example.

A12: Increment and decrement operators are used to increase or decrease the value of a variable by 1. These operators are represented by ++ and –.

 

e.g. a = 5; a++; (now here a becomes 6)

 

13: What will be the output of following code int a, b=5; b++; a=b++; a++; a=++b; printf(“%d %d”, a,b);

A13: 8 8.

 

Please follow me for more Assignment....


14     List bitwise operators in C language with example. OR

List out any four bit wise operators with their meaning and example.****

 

1.    Bitwise AND (&): Performs a bitwise AND operation between corresponding bits of two integers.

2.    Bitwise OR (|): Performs a bitwise OR operation between corresponding bits of two integers.

3.    Bitwise XOR (^): Performs a bitwise exclusive OR (XOR) operation between corresponding bits of two integers.

4.    Bitwise NOT (~): Inverts the bits of a single integer, changing 1s to 0s and vice versa.

 

15: Explain use of comma operator with one example. Or Explain sizeof() and comma operator with example.

A15: Comma operator is used to combine the various expression.

e.g. a = (x = 3, y = 4, x + y); (Here the value of a is 7).

 

16: Find the false statement :

(I) & represents Bitwise AND

(II) | represents bitwise

(III) ^ represents Bitwise exclusive OR

(IV) >> represents shift eft

 

Please follow me for more Assignment....


17: Explain priority of operator with example.

The priority of operators in C determines the order in which they are evaluated in an expression.

Priority of operators from higher to lower are as follow:

 

Parenthesis – Unary Logical – Arithmetic – Bitwise – Relational – Bitwise AND – Bitwise XOR – Bitwise OR – Logical – Conditional – Assignment – Comma.

 

 

Operators with higher priority are evaluated first. Parentheses () are used to override the default precedence.

 

18: Write the o/p of (10+10)/10*10-10.

A18: 10.

 

19: Evaluate the following expression.

1. (125*(-3)-42)(19+432%66)

= (-375 - 42)(19 + 36)

= (-417) (55)

= -22,935

 

Please follow me for more Assignment....


2. 20.0 – (5.5/(0.5*10.0))+15.0

= 20.0 – (5.5/(5)) + 15.0

= 20.0 – (1.1) + 15.0

= 20.0 – 1.1 + 15.0

= 36.1

 

20: Remove all redundant parentheses from the following expression.

 

1. (9-(65/7) +60) %26)+40.

= (9−65/7+60)%26 + 40.

2. (4*(-11)/3-(((20%5)*8)-14)

= 4*−11/3−(20%5*8−14)

 

21: What is the use of %d, %u, %i, %o, %x, %h and %l ?

A21:

1.    %d: For printing or scanning integers.

2.    %u: For printing or scanning unsigned integers.

3.    %i: For printing or scanning integers in either decimal, octal, or hexadecimal format.

4.    %o: For printing or scanning integers in octal format.

5.    %x: For printing or scanning integers in hexadecimal format.

6.    %X: Prints hexadecimal digits in uppercase.

7.    %h: Conjunction with integer format specifiers to indicate a short int.

8.    %l: Conjunction with integer format specifiers to indicate a long int.


Please follow me for more Assignment....



22: Explain special operators in detail.

A22:

Comma Operator (``,`):

Syntax: expr1, expr2, ..., exprn;

It evaluates multiple expressions, returning the result of the last expression.

 

Sizeof Operator:

Syntax: sizeof(type) or sizeof expression;

It returns the size, in bytes, of a type or an expression.

 

Address-of Operator (&):

Syntax: &variable

It returns the memory address of a variable.

 

Pointer Dereference Operator (*):

Syntax: *pointer

It accesses the value stored at the memory address pointed to by a pointer.

 

Member Access Operator (->):

Syntax: structure_pointer->member

It is used to access a member of a structure through a pointer to that structure.

 


25: List various output flags used in formatted output c statement.

A25: Some commonly used output flags in the format specifier:

 

1.    (Hyphen/Minus): Left-justify the output within the given field width.

2.    + (Plus): Display the sign of a signed number, both positive and negative.

3.    0 (Zero): Pad with zeros instead of spaces.

4.    # (Sharp/Hash): For o, x, or X conversions, prefix the output with 0, 0x, or 0X, respectively.

5.    (Space): Leave a space before positive numbers.

6.    * (Asterisk): Use dynamic width or precision specified by an additional integer argument.

 

26: List the input statement in C.

A26: 1. scanf();

2. gets();

3. getch();

4. getc();

 

27: Write C statement for

1) N=( ax3 + bx2 + c) ÷ ( dx2 +e2 )

N = (a * 3 + b * 2 + c) / (d * 2 + e * 2)

2) Y= ax2 + bx2, Z=x+ a2 +b2

Y = a * 2 + b * 2, Z = x + a * 2 + b * 2.

 

28: Show how 9mn / p+1-1/3(a + b) evaluated in c.

Let m = 1, n = 2, p = 3, a = 1, b = 2.

Ans = 7

 

Please follow me for more Assignment....


29: Show how 9+8/2*7-5 evaluated in c.

A29: 9 + 4 * 7 – 5

9 + 28 – 5

37 – 9

32

 

30: If b=10 and c=5 hen what will be the values of a ,b and c after the execution of following statement:

a = b++ - c*2;

A30:

a = 0

b = 11

c = 5

 

Please follow me for more Assignment....

 

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.