Computer Notes 10th Class 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Computer Science Notes Grade: 10th

Chapter 1:Introduction to Programming

1. Define computer program. provide input and get output.


Ans. The set of instructions given to the 9. Writer down the name of some IDEs
computer is known as a computer program for C programming language.
or software. Ans. 1) Visual Studio 2) Xcode
2. What is computer programming? 3) Code::Blocks 4) Dev C++
Ans. The process of feeding or storing the 10. What is the purpose of text editor?
instructions in the computer is known as (OR) What is text editor?
computer programming. Ans. A text editor is a software that allows
3. Who is programmer? programmers to write and edit computer
Ans. The person who knows how to write programs. All IDEs have their own
a computer program correctly is known as specific text editors.
a programmer. 11. What is the purpose of compiler in C
4. Who and when C language was language? (OR) What is compiler?
developed? Ans. A compiler is software that is
Ans. C language was developed by Dennis responsible for conversion of a computer
Ritchie between 1969 and 1973 at Bell program written in some high level
Laboratories. programming language to machine
5. What is programming language? language code.
Ans. Programmers write computer 12. What is syntax?
programs in some special languages called Ans. The set of rules used to write an
programming languages. Java, C, C++, accurate program is known as syntax of
C#, Python are some of the most the language. Each programming language
commonly used programming languages. has its own syntax (set of rules).
6. What is programming environment? 13. What is syntax error?
Ans. A collection of all the necessary tools Ans. While programming, if proper syntax
for programming makes up a programming or rules of the programming language are
environment. It works as a basic platform not followed, the program does not get
for us to write and execute programs. compiled. In this case, the compiler
7. What is Integrated Development generates an error. This kind of error is
Environment (IDE)? called syntax error.
Ans. The software that provides a 14. What do you know about reserved
programming environment to facilitate words? Write down the name of some
programmers in writing and executing reserved words.
computer programs is known as Integrated Ans. Every programming language has a
Development Environment (IDE). list of words that are predefined. Each
8. What is GUI? word has its specific meaning already
Ans. An IDE has a graphical user interface known to the compiler. These words are
(GUI), meaning that a user can interact known as reserved words or keywords.
with it using windows and buttons to Some names of reserved words are as

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

1. Define a computer. function is generally used to hold


Ans. A computer is a device that the execution of program because
takes data as input, process that the program does not continue
data and generates the output. further until the user types a key.
2. Define printf() function? 7. Which library function is used
Ans. printf() is a built-in function to include getch()?
in C programming language to Ans: To use this function, we need
show output on screen. Its name to include the library <conio.h> in
comes from "print formatted" that the header section of program.
is used to print the formatted 8. What is statement terminator?
output on screen. Ans. A statement terminator is
3. What is format specifier? identifier for compiler which
Ans. Format specifiers are used to identifies end of a line. In C
specify format of data type during language semi colon (;) is used as
input and output operations. Format statement terminator.
specifier is always preceded by a 9. What is the purpose of escape
percentage (%) sign. sequence in C language?
4. Write down the format Ans. Escape sequence is used in
specifiers against different data printf() function inside the double
types in C language. quotes (" "). It forces printf() to
Ans. Format specifiers against change its normal behaviour of
different data types in C language showing output.
are as follows: 10. What is formation of escape
Data type Format Specifier sequence?
int % d or % i Ans. Escape sequence consists of
float %f two characters. The first character
char %c is always back slash (\) (also
5. What is the purpose of known as escape character) and
scanf()? the second character varies
Ans. scanf() is a built-in function according to the functionality that
in C language that takes input we want to achieve.
from user into the variables. We 11. What is the purpose of new
specify the expected input data line (\n)?
type in scanf function with the Ans. After escape character(\), n
help of format specifier. specifies movement of the cursor
6. What is the use of getch()? to start of the next line. This
Ans. getch() function is used to escape sequence is used to print the
read a character from user. The output on multiple lines.
character entered by user does not 12. What is the purpose of Tab
get displayed on screen. This (\t)?

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

side. Double equal operator (==) 28. What is OR operator (||)?


checks whether right and left Ans. OR operator accepts Boolean
operands are equal or not. Single expression and returns true if at least
equal operator (=) assigns right one of the operands is true.
operand to the variable on left side. 29. Make the truth table for OR
24. What is difference between logical operator.
operator and arithmetic operator? Ans. The truth table for OR operator
Ans. Logical Operator is shown below:
Expression 1 Operator Expression 2 Result
Logical operators perform False || False False
operations on Boolean expression False || True True
True || False True
and produce a Boolean expression True || True True
as a result. AND (&&), OR (||),
and NOT(!) operators are
30. What is NOT operator (!)?
examples of logical operator.
Arithmetic Operator Also make its truth table.
Arithmetic Operators are used to Ans. NOT operator negates or
perform arithmetic operations on reverses the value of Boolean
data. Division, multiplication, expression. It makes it true, if it is
addition, subtraction and modulus false and false if it is true. The truth
operators are examples of table for NOT operator is given
arithmetic operator. below:
Expression Operator Result
25. Write down the name of True ! False
logical operator. False ! True
Ans. The logical operators are as 31. Differentiate between Unary
follows: and Binary Operators.
Operator Description Ans.Unary Operators
&& Logical AND Unary operators are applied over
II Logical OR one operand only e.g. logical not (!)
! Logical NOT operator and Sign operator (-)
26. What is AND operator (&&)? Binary Operators
Ans. AND operator && takes two Binary operators require two operands to
Boolean expressions as operands perform the operation e.g. arithmetic
and produces the result true if both operators, relational operators, logical
of its operands are true. It returns AND and Logical OR operators.
32. What is Operators' Ans. Precedence tells which
Precedence? operator should be performed
Prepared by: Saima Shafeeq (GGHS MC Lady Park), Jawad Arshad ( GHS Sutlej), Salar Haider ( GHS Ashraf ul Madaras)
6
first. An operator with higher *,/,% 3
precedence is evaluated before the +, - 4
operator with lower precedence. >, <, >=,<= 5
Note: In case of equal precedence, ==, != 6
the operator at left side is && 7
evaluated before the operator at II 8
right side. = 9 (Lowest)
33. Describe the precedence of 34. Define ternary operator?
different operators? Ans: The operator applied on three
Ans: operands in C programming
Operator Precedence Language is called ternary
() 1 (Highest) operator.
! 2

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.

Chapter 4:Data And Repetition

1. Define data structure. 5. What is an array


Ans: Data structure is a container initialization?
to store collection of data items in Ans: Assigning values to an array
a specific layout. for the first time, is called array
2. What is an array? initialization. An array can be
Ans: An array is a data structure initialized at the time of its
that can hold multiple values of declaration, or later.
same data type. It stores all the 6.How can we initialize an
values at consecutive locations array?
inside the computer memory. Ans: Array initialization at the
3.How can we declare an array? time of declaration can be done in
Ans: In C language, an array can the following manner.
be declared as follows: Data_type array_name[N]={value,
data_type array_name[array_size] value2,value3,……..valueN}
4. How can we declare an array 7. Write down the example of
of float type? declaration and initialization of
Ans: The example of the an array.
declaration of a float type array Ans: float height[7]={6.7, 6.2, 6.9,
that holds marks of 20 students are 6.1, 6.0, 6.6, 6.2};
given below. 8. What is the disadvantage if we
float marks[20]; do not initialize an array at the
time of declaration?
Prepared by: Saima Shafeeq (GGHS MC Lady Park), Jawad Arshad ( GHS Sutlej), Salar Haider ( GHS Ashraf ul Madaras)
9
Ans: If we do not initialize an for a specific/preset number of
array at the time of declaration, times.
then we need to initialize the array 14. Write down the general
elements one by one. It means that syntax of for loop.
we cannot initialize all the Ans: In C programming language,
elements of array in a single for loop has the following general
statement. syntax:
9. How can we access array for (Initialization; condition;
elements? What is the use of Increment/decrement)
index in an array? {
Ans: Each element of an array has Code to repeat
an index that can be used with the }
array name as array_name[index] 15.Draw a flow chart of for loop.
to access the data stored at that
particular index.
10. What is loop?
Ans: If we need to repeat one or
more statements, then we use
loops.
Example: if we need to write
Pakistan thousand times on the
screen, then instead of writing
printf ("Pakistan"); a thousand
times, we use loops.
11. How many types of loops are
provided by C language?
Ans: Following three structures of 16. Which part of for loop is
loops are provided by C language: executed first?
For loop Ana: Initialization is the first part
While loop to be executed in a for loop.
Do While loop 17. What do you mean by
12. Why do we need loops? iteration in a loop?
When do we use loops? Ans; Each run of a loop is called
Ans: Repetitive tasks are common an iteration
in programming and loops are 18.How does an array differ
essentials to save time and from simple variable?
minimize errors. Loops make code Ans. An array can store multiple
more manageable. values where a simple variable can
13.What is for loop in C store only one value.
language? 19. Is loop a data structure?
Ans. A for loops is repetition Justify your answer.
control structure that allows us to Ans. A loop is not a data structure.
execute a code (set of statements) A loop is programming construct

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

1. What is a good problem 5. What are user defined


solving approach? Or what is functions?
divide and conquer approach of Arts: The functions which are
problem solving? defined by a programmer to
Ans. In a good problem-solving perform specific tasks are called
approach, a problem is divided user-defined functions. These
into small problems. The smaller functions are written according to
problems can be solved separately the exact need of the user.
to find the solution of the problem 6. What are the advantages of
and then integrating all the functions?
solutions. This problem solving Ans. Following are the advantages
approach is called divide and of functions:
conquer. • Reusability
2. What do you know about • Separation of task
functions in C language? • Readability
Ans. A function is a block of • Handling the Complexity of
statements which performs a the problem.
particular task, e.g. printf() is used 7. Define reusability?
to display output on the screen. Ans: Functions provide reusability
3. Write down the types of of code by calling the function
functions. whenever we need to use it.
Ans. There are basically two types 8. What is meant by separation
of functions: of task using functions?
Built-in Functions Ans: Functions allow us to
User Defined Functions separate the code of one task from
4. Define built in functions? the code of other tasks. If we have
Ans: The functions which are a problem in one function, then we
available in C standard library are do not need to check the whole
called built-in functions. These program for removing the
functions are also called library problem.
functions. For example, printf()
and scanf() are built in functions.
Prepared by: Saima Shafeeq (GGHS MC Lady Park), Jawad Arshad ( GHS Sutlej), Salar Haider ( GHS Ashraf ul Madaras)
11
9. How does readability of return_type function_name (data_type_var1,
data_type var2,……….,data_type varN)
program improve?
{
Ans: Dividing the program into
body of the function
multiple functions, improves the
}
readability of the program.
16. Can a function return more
10. How does complexity of the
than one values?
problem reduce?
Ans. No, a function cannot return
Ans: If we write the whole
more than one values.
program as a single procedure,
17. Write down the general
management of the program
structure to make a function
becomes difficult. Functions
call?
divide the program into smaller
Ans. Following is the general
units, and thus reduce the
structure used to make a function
complexity of the problem.
call:
11. What is the use of functions function_name(valuel, value2,…..,valueN);
signature? 18. Differentiate between
Ans, Function signature is used to arguments and parameters of
define the inputs and output of a the function.
function. Ans. The values passed to the
12. Write down the general function are called arguments,
structure of a function whereas variables in the function
signature. definition that receive these values
Ans, The general structure of a are called parameters of the
function signature is as follows: function.
return_type function_name (data_type1,
19.What is the role of “return”
data_type2,...,data_typeN)
inside the function?
13. What is parameter of
Ans. Inside the function, “return”
function?
is a keyword that is used to return
Ans: Inputs of a function are
a value to the calling function.
called parameters of the function.
20. What is meant by body of a
14.What do you mean by return
function?
value of a function?
Ans. Body of a function is the set
Ans.Output of the function is
of statements which are executed
called its return value. A function
to fulfil the specified task. These
cannot return more than one value.
are enclosed in curly braces { }.
15.What is meant by defining a
21.Enlist the parts of function
function? Write the general
definition.
structure of defining a function?
Ans. A function definition has the
Ans, The function signature does
following parts.
not describe how the function
performs the task assigned to it. • Return type
Function definition does that. A • Function name
function definition has the • Parameters
following general structure. • Body of the function

Prepared by: Saima Shafeeq (GGHS MC Lady Park), Jawad Arshad ( GHS Sutlej), Salar Haider ( GHS Ashraf ul Madaras)
12

You might also like