0% found this document useful (0 votes)
5 views3 pages

10th Computer Science Questions-Answers CH# 2

The document provides a series of questions and answers related to C programming concepts, including the differences between various functions, operators, and format specifiers. Key topics covered include the usage of printf and scanf functions, statement terminators, escape sequences, and the distinctions between arithmetic, assignment, relational, and logical operators. Additionally, it explains unary and binary operators, as well as the conditional operator.

Uploaded by

salimkasuri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

10th Computer Science Questions-Answers CH# 2

The document provides a series of questions and answers related to C programming concepts, including the differences between various functions, operators, and format specifiers. Key topics covered include the usage of printf and scanf functions, statement terminators, escape sequences, and the distinctions between arithmetic, assignment, relational, and logical operators. Additionally, it explains unary and binary operators, as well as the conditional operator.

Uploaded by

salimkasuri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Computer Notes 2.

0
 Q1: What is the difference between printf and
scanf functions?

Ans: Printf function: The printf function is used to print text and
values on the screen in a specified format. It's also called
formatted output function.

Scanf function: The scanf function is used to get values into


variables from the keyboard during the execution of a program.
The value is input into a variable in a specified format.

 Q2: Write a note on statement terminator.

Ans: Semicolon (;) is entered at the end of a statement in C


language. It indicates the compiler that the statement ends here. If
a statement is not terminated with semicolon, C compiler will give
an error message during compilation and the program will not be
compiled.

 Q3: What do you know about format specifier?


Give two examples.

Ans: Format Specifiers: A format specifier is a computer code


that tells about the data type, field width and the format according
to which a value is to be printed or read from an input device.
Example: Decimal integer (%d), Floating-point decimal notation
(%f).

 Q4: What is the difference between integer and


floating point format specifiers?

Ans: Integer Format Specifier: The format specifier “%d” is used


to read or print a decimal integer and the “%Id” is used with long
integers.
Floating-point Format Specifier: The format specifier “%f” is
used to read and print floating-point numbers in decimal notation,
“%e” is used to read and print floating-point numbers in
exponential notation and “%g” is used to print floating-point
numbers in decimal or exponential notation whichever is shorter.

 Q5: Why we use “char” format specifier?

1
Ans: The character format specifier “%c” is used to read or print a
single character.

 Q6: Write a note on escape sequence. Give


example.

Ans: Escape Sequence: The special characters used in C


language to control printing on the output device are called escape
sequences. It is a combination of backslash (\) and a code
character.
Example: “\a” produces an alert (bell) sound.

 Q7: What is the difference between arithmetic


and assignment operator?

Ans: Arithmetic operator: Arithmetic operators are used to


perform arithmetic operations that include addition, subtraction,
multiplication, division and also to find the remainder obtained
when an integer is divided by another integer.
Assignment operator: Assignment operators are used to assign
values to variables used in computer programs.

 Q8: What is the difference between basic and


compound assignment operator?
Ans: Basic assignment operator: The basic assignment
operator is “=”. This is used to assign value of an expression to a
variable. It has the general form:
Variable = expression OR sum = a + b;
Compund assignment operator: Suppose op represents an
arithmetic operator. Then, the compound assignment operator has
the following general form to assign value of an expression to
variable:
Variable op = expression OR sum += n;

 Q9: What is the difference between relational


and logical operator?
Ans: Relational operator: Relational operators are used to
compare two values of the same type. These are used in
expressions when a decision is to be based on a condition.
Logical operator: Logical operators are used for building
compound conditions. We have seen before that a single condition
is built using a relational operator in an expression.

 Q10: What is the difference between increment


and decrement operator?

2
Ans: Increment operator is “++” and decrement operator is “- -”. ++
increments by 1 and - - decrements by 1.

 Q11: What is the difference between


assignment and equal to operator?

Ans: The assignment operator (=) is used to assign a value to a


variable WHEREAS the equal to operator (==) is used to compare
two values of the same data type.
a=5; --> Assignment operator
a= =1 --> Equal to operator

 Q12: What is the difference between unary and


binary operators?

Ans: Unary operator: The operators that work with a single


operand are known as unary operators. Unary operators are -, ++,
-- and the logical operator ! (NOT).
Binary operator: The operators that work with two operands are
known as binary operators. Binary operators are -, +, *, \, % and
logical operators && (AND) and || (OR).

 Q13: Write a note on conditional operator.

Ans: A conditional operator is a decision-making operator. It has


the following form:

condition? expression1 : expression2;

When this statement is executed, the condition is evaluated. If it is


true, the entire conditional expression takes on the value of
expression1. If it is false, the conditional expression takes on the
value of expression2.
Some programmers may prefer to use the if-else statement rather
than using the conditional operator because it is easy to
understand.

You might also like