Computer Notes 10th Class 1
Computer Notes 10th Class 1
Computer Notes 10th Class 1
Prepared by: Saima Shafeeq (GGHS MC Lady Park), Jawad Arshad ( GHS Sutlej), Salar Haider ( GHS Ashraf ul Madaras)
1
follows: auto, int, else, switch , if,and small case letters, we cannot capitalize any
return. letter i.e. int is different from Int.
(ii) Each statement ends with a semi-
15. Write down the name of main parts colon; symbol.
of structure of a C program. 22. What are comments?
Ans. A program can be divided into three Ans. Comments are the statements in a
main parts: program that are ignored by the compiler
1. Link section or header section: and do not get executed. Usually
2. Main section comments are written in natural language.
3. Body of main () function: 23. Write down the purpose of writing
16. What is link section or header comments?
section? Ans. 1) It facilitates other programmers to
Ans. Header section or link section is the understand our code.
part of program where header files are 2) It helps us to understand our own code
included using include statement. even after years of writing it.
17. What is meant by header files? 24.How many types of comments are?
Before using the existing functions in C Ans. In C programming language, there
language, we need to include the files are two types of comments:
where these functions have been defined. 1. Single-line Comments
These files are called header files. We add 2. Multi-line Comments
these header files in our program by using 25.What is the difference between single
include statement. <stdio.h>, <conio.h> -line comments and multi-line
and <math.h> are some examples of comments?
header files used in C language. Ans. a) Single-line comments start with //.
18. Write down the general structure of Anything after // on the same line, is
an include statement. considered a comment. For example,
Ans. General Structure of an include //This is a comment.
statement is as follows; b) Multi line comments start with /* and
#include<header_file_name>. end at */. Anything between /* and */ is
19. What is main section of C language? considered a comment, even on multiple
Ans. It consists of a main function. Every lines. For example,
C program must contain a main() function /*this is
and it is the starting point of execution. a multi- line comment */
20. What is the body of main () 26. What do you know about constants?
function? Constants are the values that cannot be
Ans. The body of main() is enclosed in the changed during the execution of a program
curly braces { }. All the statements inside e.g. 5, 75.7, 1500 etc.
these curly braces make the body of main 27. How many types of constants are in
function. C language?
21. Write down any two key points to In C language, there are three types of
write C Language program correctly. constants:
Ans. (i) C language is case sensitive. It • Integer Constants
means that if a keyword is defined with all • Character Constants
Prepared by: Saima Shafeeq (GGHS MC Lady Park), Jawad Arshad ( GHS Sutlej), Salar Haider ( GHS Ashraf ul Madaras)
2
• Real Constants 32. Write down any three rules for
28. How you can explain integer naming variables.
constants? (i).A variable name can only contain
Ans. These are the values without a alphabets (uppercase or lowercase) digits
decimal point e.g. 7, 1256, 30100, 53555, - and underscore sign.
54, -2349 etc. It can be positive or (ii)Variable name must begin with a letter
negative. or an underscore; it cannot begin with a
digit.
29. Differentiate between real constants (iii) A reserved word cannot be used as a
and character constants? variable name.
Ans. Real Constants 33. What is variable declaration?
These are the values including a decimal Ans. Declaring variable means specifying
point e.g. 3.14, 15.3333, 75.0, -1575.76, - its data type and giving it a valid name.
7941.2345. They can also be positive or Following syntax can be followed to
negative. declare a variable.
Character Constants Data_type variable_name;
Any single small case letter, upper case 34.What is variable initialization?
letter, digit, punctuation mark, special Ans. Assigning value to a variable for the
symbol etc enclosed within ' ' is first time is called variable initialization. C
considered a character constant e.g. '5', '7', language allows us to initialize a variable
'a' , 'X', '.' etc. both at the time of declaration, and after
30.What is variable? declaring it.
Ans. A variable is actually a name given to 35.Write down structure for initializing
a memory location, as the data is variable.
physically stored inside the computer's Ans. For initializing a variable at the time
memory. The value of a variable can be of declaration, we use the following
changed in a program. general structure.
31. How many data types of a variable data_type variable_name = value;
are? 36. Differentiate between char and int.
Ans. The data types of variable are as Ans. Integer data type(int) is used to store
under: integer value while character data type
• Integer - int (signed/unsigned) (char) is used to store one character only
• Floating Point – float
• Character – char
Prepared by: Saima Shafeeq (GGHS MC Lady Park), Jawad Arshad ( GHS Sutlej), Salar Haider ( GHS Ashraf ul Madaras)
3
Chapter 2:User Interaction
Prepared by: Saima Shafeeq (GGHS MC Lady Park), Jawad Arshad ( GHS Sutlej), Salar Haider ( GHS Ashraf ul Madaras)
4
Ans. Using \t takes cursor to the Ans. Multiplication operator (*) is
next tab stop horizontally. A tab a binary operator which performs
stop is collection of 8 spaces. the product of two numbers.
This escape sequence is used e.g. int multiply = 5 • 5;
when user presents data with more After the execution of statement,
spaces. the variable multiply contains value
13. What is operator? 25.
Ans. An operator, in a 19. What is an Addition operator?
programming language, is a Ans. Addition operator (+)
symbol that usually represents an calculates the sum of two operands.
action or process. It tells the e.g. int add = 10 + 10;
compiler to perform specific Resultant value in variable add is
mathematical, relational or logical 20.
operation and produce final result. 20. What is Subtraction
14. Write down the name of basic operator?
operator? Ans. Subtraction operator (-)
Ans: Following is the list of some subtracts right operand from the left
basic operator types: operand.
• Assignment operator e.g. int result = 20 - 15;
• Arithmetic operator After performing subtraction, value
• Logical operator 5 is assigned to the variable result.
• Relational operator 21. What is Modulus operator?
15. What is assignment Ans. Modulus operator (%)
operator? performs divisions of left operand
Ans. Assignment operator is used by the right operand and returns
to assign a value to a variable, or the remainder value after division.
assign a value of variable to Modulus operator works on integer
another variable. Equal sign (=) is data types.
used as assignment operator in C. int remaining = 14 % 3;
16. What is the use of an When we divide 14 by 3, we get a
arithmetic operator? remainder of 2, so the value
Ans. Arithmetic Operators are used stored in variable remaining is 2.
to perform arithmetic operations on 22. Why relational operators
data. are used in C language?
17. What Is division operator? Ans. Relational operators
Ans. Division operator (/) divides compare two values to determine
the value of left operand by the the relationship between values.
value of right operand. Relational operators identify either
e.g.Float result = 3.0 / 2.0; the values are equal, not equal,
After the statement, the variable greater than or less than one
result contains the value 1.5. another. C language allows us to
18. What is multiplication perform relational operators on
operator? numeric and char type data.
Prepared by: Saima Shafeeq (GGHS MC Lady Park), Jawad Arshad ( GHS Sutlej), Salar Haider ( GHS Ashraf ul Madaras)
5
23. What is difference between false if any of the operands is
Assignment operator and equal false.
to operator? 27. Make the truth table for AND
Ans. In C language, equal to (==) operator.
operator is used to check for The truth table for AND operator is
equality of two expressions, shown below:
Expression1 Operator Expression2 Result
whereas assignment operator (=) False && False False
assigns the result of expression on False && True False
True && False False
right side to the variable on left True && True True
Prepared by: Saima Shafeeq (GGHS MC Lady Park), Jawad Arshad ( GHS Sutlej), Salar Haider ( GHS Ashraf ul Madaras)
7
Chapter 3:Conditional Logic
1. What do you know about control Ans: If statement has the following
statements? structure in C language:
Ans: Control statements are used to if (condition)
control the flow of execution of a program.
2. What are the types of control Associated Code
statements? 8. What is the purpose of “if” in if
Ans: There are three types of control statement structure?
statements in C language. Ans: “if” is a keyword that is followed by
Sequential Control Statement a condition inside parentheses().
Selection Control Statement 9. Draw a flow chart to shows the basic
Repetition Control Statement flow of if statement.
3. What is sequential control
statement?
Ans: Sequential control statement is the
default control structure in C language.
According to the sequential control, all the
statements are executed in the given
sequence.
4. What are selection control
statements?
Ans: The statements which help us to 10. Draw the flow chart for the
decide which statements should be structure of if-else statement.
executed next, on the basis of conditions,
are called selection statements.
5. How many types of selection
statement are in C language?
Ans: There are two types of selection
statements.
if statement
if-else statement
6. What is the use of if statement?
Ans: C language provides if statement in
which we specify a condition, and
associate a code to it. The code gets 11.Why if-else statement is used
executed if the specified condition turns in C language?
out to be true, otherwise the code does not Ans: It executes the set of
get executed. statements under if statement if the
7. Write down the structure/syntax of if condition is true, otherwise
statement.
Prepared by: Saima Shafeeq (GGHS MC Lady Park), Jawad Arshad ( GHS Sutlej), Salar Haider ( GHS Ashraf ul Madaras)
8
executes the set of statements Ans: In a compound statement, it
under else statement. is a common mistake to omit one
12. Write down the general or two braces while typing.
structure of if-else statement? 15. What is meant by condition?
Ans: General structure of the if- A condition could be any valid expression
else statement is as follows: including arithmetic expressions, relational
if (condition) expressions, logical expressions, or a
Associated Code combination of these.
else 16. Define switch case structure.
Associated Code The switch case allows us to execute one
13. Define compound statement.
code block among many alternatives.
Ans: A set of multiple instructions
17.What is meant by conditional
enclosed in braces is called a block
logic?
(enclosed in curly braces) or a
Conditional logic refers to
compound statement.
executing different actions in a
14. What is common mistake
program based on whether certain
made in a compound statement?
conditions are met.
Prepared by: Saima Shafeeq (GGHS MC Lady Park), Jawad Arshad ( GHS Sutlej), Salar Haider ( GHS Ashraf ul Madaras)
10
that allows a program to do an 21. What is counter variable?
action repetitively as long as the Ans. A variable which starts with
conditions defined for loop are an initial value and determines the
met. duration of repetition is known as
20. What are nested loops? counter variable.
Ans. When we use a loop inside
another loop, it is called nested
loop.
Chapter 5: Functions
Prepared by: Saima Shafeeq (GGHS MC Lady Park), Jawad Arshad ( GHS Sutlej), Salar Haider ( GHS Ashraf ul Madaras)
12