10th Class Computer New Course User Interaction Unit-02

10th Class Computer New Course User Interaction Unit-02

Q.1 Multiple choice questions.

  1. printf is used to print ____________________ type of data.

a) int

b) float

c) char

d) All of them (Correct Answer)

2. scanf is a ____________________ in C programming language.

a) keyword

b) library

c) function (Correct Answer)

d) none of them

3. getch() is used to take ____________________ as input from user.

a) int

b) float

c) char

d) all of them (Correct Answer)

4. Let the following part of code, what will be the value of variable a after execution:

int a = 4;

float b = 2.2;

a = a*b;

a) 8.8

b) 8 (Correct Answer)

c) 8.0

d) 8.2

5. Which of the following is a valid line of code.

a) int = 20;

b) grade = ‘A’; (Correct Answer)

c) line = this is a line

d) none of these

6. Which operator has highest precedence among the following:.

a) /

b) =

c) >

d) ! (Correct Answer)

7. Which of the following is not a type of operator:

a) Arithmetic operator

b) Check operator (Correct Answer)

c) Relational operator

d) Logical operator

8. The operator % is used to calculate ____________________.

a) Percentage

b) Remainder (Correct Answer)

c) Factorial

d) Square

9. Which of the following is a valid character:

a) ‘here’

b) “a”

c) ‘9’ (Correct Answer)

d) none of them

10. What is true about C language:

a) C is not a case sensitive language

b) Keywords can be used as variable names

c) All logical operators are binary operators

d) none of them (Correct Answer)

Q.2 True or False

  1. Maximum value that can be stored by an integer is 32000.

False

2. Format specifiers begin with a % sign.

True

3. Precedence of division operator is greater than multiplication operator.

False

4. getch is used to take all types of data input from user.

True

5. Scanf is used for output operations.

False

Q.3 Define the following.

1) Statement Terminator

A statement terminator is identifier for compiler which identifies end of a statement. In C language semi colon(;) is used as statement terminator.

2) Format Specifier

Format specifier are used to specify format of data type during input and output operations. Format specifier is always preceded by a percentage (%) sign.

3) Escape Sequence

Escape sequence forces printf to escape from its normal behavior. It is the combination of escape character (\) and a character associated with special functionality.

4) scanf

scanf is a built-in function in C language that takes input from user into the variable.

5) Modulus Operator

Modulus operator is a binary operator, which performs division of left operand to the right operand and returns the remainder value after division. Modulus operator works on integer data type.

Q.4 Briefly answer the following questions.

1) What is the difference between scanf and getch?

Answer: Difference between scanf and getch

scanf is a built-in function in C language that takes input from user into the variables. We specify the expected input data type in scanf function with the help of format specifier, while getch() function is used to read a character from user. The character entered by user does not get displayed on screen. This function is generally used to hold the execution of program because the program does not continue further until the user types a key.

2) Which function of C language is used to display output on screen?

Answer:

printf is a built-in function in C programming language to show output on screen. Its name comes from “print formatted” that is used to print the formatted output on screen.

3) Why format specifiers are important to be specified in I/O operations?

Answer: Importance of Format Specifiers

If we want to display the value of a variable then we use format specifiers. For example if want to show int type data, then we must specify it inside the printf by using format specifier %d or %i. In the same way, for float type data we must use %f.

Without these format specifiers we cannot get the value of the variables in printf.

4) What are escape sequences? Why do we need them?

Answer: Escape Sequence

Escape sequences are used in printf function inside the “and “. They force printf to change its normal behavior of showing output.

5) Which operators are used for arithmetic operations?

Answer: Arithmetic Operators

Operator Description
/ (Divide)
Divide the left side value by a right side value
* (Multiply)
Used to multiply two values
+ (Add)
Used to add two values
- (Subtract)
Used to subtract two values
% (Mod)
It gives the remainder value after dividing the left value by right value

6) What are relational operator? Describe with an example.

Answer: Relational Operators

Relational operators compare two values to determine the relationship between values. Relational operators identify either the values are equal, not equal, greater than or less than one another.Relational operators perform operations on two operands and return the result in Boolean expression (true or false).
Operator Example Explanation Result
== (equal to)
5==5
5 equal to 5
True
!= (not equal to)
5!=7
5 not equal to 7
True
> (greater than)
5>7
5 greater than 7
False
< (less than)
5<7
5 less than 7
True
>= (greater than equal to)
5>=5
5 greater than or equal to 5
True
<= (less than equal to)
5<=4
5 less than or equal to 4
False

7) What are logical operators? Describe with an example.

Answer: Logical Operators

Logical operators perform operations on Boolean expressions and produce a Boolean expression as a result. Logical operations are used to evaluate more than one relational expressions.

Operator Example Explanation Result
&& (logical AND)
38
3 is less than 4 AND 7 is greater than 8
False
|| (logical OR)
3==4 || 3>1
3 is equal to 4 OR 3 is greater than 1
True
! (logical NOT)
!(4>2 || 2==2)
NOT (4 is greater than 2 OR 2 is equal to 2)
False

8) What is the difference between unary operators and binary operators?

Answer: Difference between unary and binary operators

Unary operators require one operand to perform the operation, while the binary operator require two operands to perform the operation.

9) What is the difference between == operator and = operator?

Answer: Difference between == operator and = operator

== Operator is used to check whether the value on left hand side is equal to the value at the right hand side, while = is used to assign the value (right hand side operand) to a variable (left hand side operand).

10) What is meant by precedence of operator? Which operator has the highest precedence in C language?

Answer: Operators’ Precedence

If there are multiple operators in an expression, the question arises that which operator is evaluated first. To solve this issue, a precedence has been given to each operator. An operator with higher precedence is evaluated before the operator with lower precedence. In case of equal precedence, the operator at left side is evaluated before the operator at right side.

Operator with highest precedence:

() operator has the highest precedence among all operators.

Recommended

9th Computer New Course Networks Unit-03

9th Computer New Course Networks Unit-03 3.1 Choose the correct option. The IPv4 address is made up of ____________________ binary bits. i. 31 ii. 29 iii. 32 (Correct Answer) iv. 30 2. Routing is the process of taking data from one device and sending it to another device in different ____________________. i. Channel ii. Network […]

Buy Best Stationery Products in Pakistan

Piano Ballpoint Pen

Piano Ballpoint Pen

ORO Trimetal Pencil

ORO Trimetal

Dollar Clipper Pen

UHU 10×7 ml Pack of 10 PCs

UHU 10×7 ml Pack of 10 PCs

Glue Stick 8g Pack Of 12 PCs

Glue Stick 8g

Color Pencils Box of 12 PCs

Deer Multi Color Pencils

For more stationery items please visit     :     https://stationerystore.pk