0% found this document useful (0 votes)
7 views18 pages

CH 2 Programming in C

The document provides an overview of programming concepts, focusing on the C programming language and its characteristics, including high-level languages (HLL) and assembly language. It covers definitions, differences between programming languages, variable types, constants, and the role of Integrated Development Environments (IDEs). Additionally, it explains the use of keywords, preprocessor directives, and the structure of C programs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views18 pages

CH 2 Programming in C

The document provides an overview of programming concepts, focusing on the C programming language and its characteristics, including high-level languages (HLL) and assembly language. It covers definitions, differences between programming languages, variable types, constants, and the role of Integrated Development Environments (IDEs). Additionally, it explains the use of keywords, preprocessor directives, and the structure of C programs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

PISK Computer Science GRADE 10 11

Chapter 2 1. These are easily understandable.


2. The programs written in HLL are portable.
PROGRAMMMING IN C
3. Debugging process is easy.
Q2. SHORT QUESTION 4. Written program is not machine dependent.
I. Define computer program. Features of Assembly language:
A well-defined set of instructions given to the computer to 1. These are not easily understandable. However, they are relatively
solve a problem is called a computer program easier than machine level languages.
Computer programming is the process of writing a computer 2. The programs written in Assembly languages are not portable.
program in computer language to solve a particular problem. 3. Debugging process is not very easy.
Computer program controls the operation of a computer and it is 4. Written program is machine dependent.
developed in a computer language to perform a task. IV. Write four characteristics of HLLs.
II. Differentiate between syntax and semantic 1. These languages were developed to make programming simple,
Syntax: easier and less prone to errors.
1. Syntax refers to the rules of a programming language. 2. High level languages are not machine dependent.
2. Statements are written as per syntax. 3. The process of finding and removing errors in programs (debugging)
3. It is just like the grammar of a natural language. is easier.
Semantic 4. High-level language programs are highly structured. They allow
1. Semantic gives meaning to statements of a programming language. programmers to break lengthy programs into a number of modules.
2. It describes the sequence of operations to be performed. V. Define Integrated Development Environment (IDE).
For example, in the assignment statement; IDE is computer software that brings all the processes and tools required for
Sum = a + b; program development into one place. Its aim is to make the life of
The semantic of the statement is to perform the expression, that is add the programmers easier by grouping together all the tasks needed for building
values stored in variables a and b and then store the result in variable Sum. applications into one environment. Modern IDEs has easy GUI interface.
III. Differentiate between high level and assembly language: Most of the new programming languages use IDE to create, compile and run
Features of high level language: programs.
PISK Computer Science GRADE 10 12

VI. differentiate between constant and variable? meaning and purpose. The meaning and purpose of a keyword is

A variable is a named memory location or memory cell. It is defined by the developer of the language. So they cannot be used

used to store programs input data and its computational results as variable name. They cannot be changed or redefined by the

during execution. The value of variable may change during the user. Examples include if, while, int, and const. there are nearly

execution of the program. 32 reserved word.

A constant is a quantity that cannot be changed during program Extensive questions exercise
execution. Example marks=67; Q3. Describe the following HLLs. C/C++, Visual Basic, C# and JAVA.
Here marks is variable and 67 is constant. C
It was developed in early 1970s by Dennis Ritchie at Bell Laboratories. C
VII. Which of the following are valid C variables? Give the reason if not
has become one of the most popular programming languages today. It is a
a valid variable area, 5x, Sum, net pay, float, _age, else, case, size22,
highly structured programming language which is easy to understand and
my_weight?
use. In the past, it was mainly used for writing system programs such as
1. Valid Variables:
2. my_weight, area. size22, Sum operating systems, compilers, assemblers etc. Today it is used for writing all

3. Not Valid Variables: types of application programs. For example word- processing programs,
spreadsheet programs, database management systems, educational programs,
5x A variable can’t be start with number
games etc.
Net pay Space can’t be used in variable name
C++:
Float Data types can’t be used in variable name
C++ was developed by Bjarne Stroustrup also at Bell Laboratories during
_age Special character (_) can’t be used in variable name
1983- 1985. C++ is a superset of C, meaning that any valid C program is
Else Commands cannot be used as variable name also a valid C++ program. The purpose of developing C++ was to provide
Case Commands cannot be used as variable name programming facilities to easily and quickly write more powerful programs.
VIII. What is keyword or reserved word? Why not can be Visual Basic:
used as variable. Visual Basic (VB) is a high level language which evolved from the earlier

Keyword is a word in C++ language that has a predefined version called BASIC. BASIC stands for Beginner’s All-purpose Symbolic
PISK Computer Science GRADE 10 13

Instruction Code. VB is a very popular programming language for writing C language modules
windows and Web applications. It provides a graphical development 1. Creating and Editing a C program
environment. VB is commonly used for developing business programs such
Text editor is a simple word processor that is used to create and
as payroll system and inventory control program. The user can also write
edit source program. The process of writing C program is known
programs related with engineering, science, art, education, games etc.
as editing. It is process includes Writing, modifying and deleting
C#:
program statements.
C# (C-sharp) is a language developed in 2000 by Microsoft Corporation.
It is a simple, modern, general-purpose programming language. Syntax of 2. Compiler

C# is very similar to C and C++. It also has some features of Java. It is a A compiler is a program that converts the instruction of a high-
language that makes computer programming easy and efficient. It provides level language into machine language as a whole. The compiler
facilities to write Web applications that can be used across the internet. All converts the source program into machine code. The machine
types of programs including games, utilities, operating system, compilers, code program is known as object program.
business applications and Web based applications can be developed in C#. 3. Debugger or Interpreter
Java:
It is a software that checks each statement in the source program
Java is a high-level language developed by Sun Microsystem. It is very
line by line and generates machine instructions. That is why it is
similar in syntax to C and C++. Java is an ideal language for network
slower than compiler. It also checks syntax errors in program. A
computing. It is used for writing programs for many devices, computers and
source program containing an error cannot be executed.
networks. It is widely used in web applications. The current versions of most
4. Linker
of the Web browsers are made Java enabled.
Q4. What is C language IDE, Explain its modules in detail. The process of linking library files with object code is known as
C language IDE is computer software that brings all the processes and tools linking. A program that combines the object program with
required for program development into one place. Its aim is to make the life additional library files is known as linker. It is a part of compiler.
of programmers easier by grouping together all the tasks needed for building It combines object program and library files and saves the final
applications into one environment. Modern C/C++ IDEs has easy GUI machine language program as executable file.
interface which use IDE to create, compile and run programs.
PISK Computer Science GRADE 10 14

5. Loader access a library. Each library contains different header files/The

The program that places executable files in memory is called include preprocessor directive is used to include header files in

loader. The extension of executable files is .exe. the program.

Q5. List out different rules for declaring variables in C++. Syntax #include <header file>

i. The first character of variable must be a letter or #include <stdio.h>

underscore (Like A or _A). Where stdio.h is a header file. Header files are collection of
ii. Blank spaces are not allowed in variable names (Like A standard library functions to perform different tasks like printf
1). and scanf.
iii. Variable may include number and underscore (Like A_1). Q. what is the use of "define" preprocessor?
iv. Reserved word cannot be used as variable name (like int
The define directive is used to define a constant. It starts with the
and if).
symbol #. It is not terminated with semicolon. It can be used
v. No restriction on length of variable name, however only
anywhere in the program
first 31 characters are significant.
vi. Upper and lower cases are allowed. For example, X2, x2, Syntax #define identifier= value

fi and ABC are correct variable. Example #define PI 3.14

Q. what is preprocessor directive, what is the use of Example #define CUBE(A) (A*A*A)
"#include" preprocessor? and #include <stdio.h> # include<stdio.h>
The preprocessor directives are commands that give #define PI 3.14
instructions to C preprocessor. Preprocessor directives start with void main(void)
hash symbol # and the keyword include or define. These {
directives are written at the start of program. Two types of printf("%f",PI);
preprocessor directives used in C language are include and }
define. Like #include <stdio.h>

The "include" preprocessor directive enables a program to


PISK Computer Science GRADE 10 15

Q. What is constant qualifier? of 256 characters. C language character set contains the following set of
We use the const qualifier to declare a variable as constant. That means characters...
that we cannot change the value once the variable has been initialized. For
1. Alphabets
example,
2. Digits
const float PI=3.14;
3. Special Symbols
int main() {
const int x = 10; Alphabets
x = 12;
return 0;} /* This will show error because we are C language supports all the alphabets from the English language. Lower-

going to change constant value of x*/ and upper-case letters together support 52 alphabets.

Q. what are header files? lower case letters - a to z


Header files are collection of standard library functions to UPPER CASE LETTERS - A to Z
perform different tasks. There are many header files for different
purposes. Each header file contains different types of predefined Digits
function. The extension of a header file is .h. They include
C language supports 10 digits which are used to construct numerical values
preprocessor directive is used to include header files in
in C language.
programs. Syntax #include <header file name>
Digits - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Example1 #include “math.h”

Extra/unseen question Special Symbols

Q. Explain character set in c language. C language supports a rich set of special symbols that include symbols to
perform mathematical operations, to check conditions, white spaces,
As every language contains a set of characters used to construct words,
backspaces, and other special symbols.
statements, etc., C language also has a set of characters which
include alphabets, digits, and special symbols. C language supports a total Special Symbols - ~ @ # $ % ^ & * ( ) _ - + = { } [ ] ;
PISK Computer Science GRADE 10 16

Q. what is an identifier? Give some examples of identifier. level language into machine language as a whole. The compiler

The identifiers are the names used to represent variable, converts the source program into machine code. The machine

constants, types, functions and labels in the program. code program is known as object program.

Standard identifiers 2. Interpreter

A type of identifier that has special meaning in C is known as The interpreter checks each statement in the source program and

standard identifier. C cannot use a standard identifier for its generates machine instructions. It also checks syntax errors in

original purpose if it is redefined; printf and scanf are examples program. A source program containing an error cannot be

of standard identifiers. executed.

User-defined identifiers 3. Assembler:

The type of identifier that is defined by the programmer to An assembler is translating program that translates the

access memory location is known as user-defined identifier. The instruction of an assembly language into machine language.

user-defined identifiers are used to store data and program Q. what is a variable explain with types?
results. Some examples of user-defined identifiers are num, age, A variable is a named memory location or memory cell. It is
marks etc. used to store programs input data and its computational results
Q. what is meant by language processor? Explain different during execution. The value of variable may change during the
types of translators. execution of the program. However, the name of variable cannot

Language processor be changed. For example marks, avg and age etc. it may be up to
31 characters long.
Language processor or translator is software that converts the
programs of high-level languages into machine language. Every Types of variable

computer language has its own translators. Different types of C language provides following two types of variable.
translators include compiler, interpreter and assembler. 1. Numeric variable
1. Compiler It is used to represent numeric value. It has further two types
A compiler is a program that converts the instruction of a high
PISK Computer Science GRADE 10 17

a. integer variable variable declaration. A variable must always be declared before


b. floating point variable: it can be used in a program. The compiler gives an error if an

a. Integer variable: undeclared variable is used in a program.

Integer variable are the quantities which can hold both positive Syntax data type list of variables;

and negative numbers. Some examples of integer variable Example int marks;

A=5; B=-10; X=100; where 5, -10 and 100 are values Q. what is C known as strongly typed language?

b. floating point variable: C is a strongly typed language. It means that a variable must

Floating point variable are the quantities which can hold both always be declared before it can be used in a program. The

positive and negative numbers with fraction or decimal point. compiler gives an error if an undeclared variable is used in a
program.
Some examples of floating variable are A, B and X
Q. What is variable initialization?
A=5.5; B=-10.6; X=100.9; where 5.5, -10.6 and 100.9 are values
The process of assigning a value to a variable at the time of
II. Character variable:
declaration is known as variable initialization. The equal sign (
Any character variables are the quantities which can hold any
=) is used to initialize a variable. Variable name is written on the
singe character, number, or special character written in single
left side and the value is written on the right side of equal sign.
quotation mark. Some examples of character variable are A=
Syntax data type variables = value;
‘A’, B=‘9’, ‘=’ C= ‘$’ etc.
Example int marks =90;
String variable: A quantity that can store a collection of
characters in double quotation marks is called string variable. It Q. what is constant, explain different types of constants.
may consist of any alphabetic characters, digits and special A constant is a quantity that cannot be changed during program
symbols. For example A=“I love Pakistan” execution.

Q. what is a variable declaration? Example marks=67;


The process of specifying the variable name and its type is called Here marks is variable and 67 is constant.
PISK Computer Science GRADE 10 18

Types of constant Q. Name and give the purpose of basic data type available in

C language provides two types of constants. These are numeric C.

constants and character constants. int used to store whole numbers (integers).

I. Numeric constant float used to store a real or floating point value.

It has two types (integer and float) char stores a single character including letters, punctuation

a. Integer constants: Integer constants are numeric values marks and digits.

without fraction or decimal point. Both positive and negative


integer constant are used. The minus sign – is used for negative Q. Why does cancellation error occur?
integer constants. If no sign is used, the value is positive by
The cancellation error occurs due to the manipulation of very
default. Some examples of integer constants are 87, -10 and -5
large and very small floating numbers are manipulated. The
b. floating point constants: Floating point constants are manipulation may show unexpected result. The larger number
numeric values with fraction or decimal point. Floating point may cancel out the smaller number when both numbers arc
constants represent values that are measured. Some examples of added.
integer constants are 87.1, 45.2, -10.3 and -5.4.
Q. What is the use of character data type?
II. Character constants: Any character written single quotation
char data type is used to store character value. It takes 1 byte in
mark is called character constant. All alphabetic characters,
memory. It is used to represent a letter, number or punctuation
digits and special symbols can be used as character constants.
mark and a few other symbols. For example char ch=’a’ where
Some examples of character constants are ‘A’, ‘9’, ‘=’ and ‘$’
ch is a variable of type char.
etc.
Q. How are characters stored?
String constants: A collection of characters is called string
constants. String constant is written in double quotes. It may The characters are stored in ASCII code form. ASCII stands for

consist of any alphabetic characters, digits and special symbols. American Standard Code for Information Interchange. The

For example “I love Pakistan” (string not included in scheme) ASCII code values of characters are used when they are added,
subtracted or compared.
PISK Computer Science GRADE 10 19

Q What are comments? var=type (expression)

Comments are the lines of program that are not executed. The Implicit type casting
compiler ignores comments and does not include them in the Implicit type casting is performed automatically by the C
executable program. That is why the comments do not affect the Compiler. The operands in arithmetic operations must be of
size of executable program. similar types. If the data types of operand are different, the value
/* single line comments*/ with lower data type is converted into higher data type. Its

OR // single line comments syntax is

/* multiline var=type(expression)

Comments*/ Example V=(2.5*1 ) we shall get v=2.5

Q. Why comments do not affect the size of program? Explicit type casting

The compiler ignores comments and does not include them in Explicit casting is performed by programmer. It is performed by

the executable program. That is why the comments do not affect using cast operator. The cast operator tells the computer to

the size of executable program. convert the data type of a value. Its Syntax is
var=type(expression)
Q. Why are comments used in C Program?
Example v=int(2.5*1.0 ) we shall get v=3
Comments are used to increase the readability of the program.
Comments are notes about different lines or code that explain the Q. Where comments can be added in programs?

purpose of code. The user can insert information notes in the Comments can be added anywhere in the code. Comments can
code. It helps in debugging and modifying the program later. be added in programs into 2 ways. The user can write comments

Q. What is type casting and explain its types? on single line or on multiple lines.

The process of converting the data type of value during Q. How are comments added on single line?

execution is known as type casting. The type castings are Comments on single lines are added by using double slash ‘//’ .
implicit type casting and explicit type casting. Its syntax is Anything written on right side of double slash is considered as
PISK Computer Science GRADE 10 20

comments and is ignored during execution. Or /* comments */ 𝟑𝒚


𝒙=
𝟓−𝒛
Q. How are comments added on multiple lines?
X = (3 * y)/(5 - z) OR x = 3 * y / (5 - z)
Comments on multiple lines are added by using /* and */
symbols. Anything written between 2 symbols is considered as
comments and is ignored during execution, Q. What is data type? List different categories of data type in
C language.
Q. Write a C constant declaration that gives the name PI to
the value 3.142 ? const float PI = 3.142; The data type defines a set of values and the set of operation
on those values. Each data types require different amount of
memory. C language provides the three main data types
Q. What is the difference between literal string "area" and
1) int To store numeric values
identifier area?
2) float To store real values
The literal string “area" is a string constant value. The identifier
area is a variable to store a value. 3) char To store character values

Q.. Write a declaration statement and an assignment (input) 1. Integer data is the numeric value with no decimal point or
statement to assign 30 meter to a variable named length. fraction. It includes both positive and negative values. The minus
sign – is used to indicate negative value. If no sign is used the
int length;
value will be positive by default. Some examples of integer
length = 30;
values are 10,520 and -20
OR
Types of integer data
int length = 30;
C provides different types of integer data are
Q. Write the following statement in C: a = 2bc 3
I. 1. short int/int or short
a=2*b*c*c*c II. 2. long int or long

Q. Write the following statement in C: III. 3. unsigned int or unsigned


IV. signed int
PISK Computer Science GRADE 10 21

I. Int/short int data type:- value. If no sign is used then it is positive. Some examples of

This is used to represent integer values. An integer variable real values are 10.5, 5.3 and -10.91 etc.

stores a number with no fractional part such as 11,10 and 25 etc Types of floating pointes
.It makes 2 bytes in memory depending on the computer and I. float
compiler being used. it takes 2 bytes and its range is from -32768 II. double or double float
to +32767. III. long double or long double float

II. Unsigned/ unsigned int :- I. Float data type:

This is used to store only positive integer values. It takes 2 bytes This is used to store real values. It takes 4 bytes in memory. It
in memory. Its range is from 0 to 65,635.The unsigned int is also range from 10-38 to 1038.It provides the precision of six decimal
called unsigned. places.

III. signed/ signed int II. Double data type:

This is rarely used because default value of integer is always This is used to store large real values. It takes 8 bytes in
signed. It takes 2 bytes in memory. memory. Its range is from 10-308 to 10+308.It provides the

IV. Long/ long int: precision of fifteen decimal places

This is used to store large integer values. It takes 4 bytes in III. Long double data type:

memory. Its range from -2,147,483,647 to 2,147,483,647. This is used to store very large values. Its range 10-4932 to

Unsigned long/ Unsigned long int:- This is used to store large 10+4932.It provides the precision of nineteen decimal places. It

positive values. It takes 4 bytes in memory. It range is from 0 to takes 10 bytes of memory or double memory as double data

4,294,967,295. (Not in scheme) types.

2. Floating point data 2. Character data type:

The floating-point data is a numeric value with decimal point or This is used to store character constant values. It takes 1 bytes in
fraction. It is also called real type data. It includes both positive memory. Any character written single quotation mark is called
and negative values. The minus sign- is used to indicate negative character constant. Some examples of character data type here
PISK Computer Science GRADE 10 22

char a, b , c Machine independence means that programs written in one


language can be executed on different types of computers. For
a=‘A’,
example, a program written in C can be executed on Intel
b= ‘9’,
processors and Motorola processors.
c= ‘=’
Q.5. who is a programmer?
Q. Describe the concept of overflow and underflow with A person who develops a computer program is Called
example? programmer. The programmer develops programs to instruct the
Each types of numeric variable can store a particular minimum computer how to process data to convert into, information.
and maximum value. An error occurs if the value assigned to the Programmer uses programming languages or tools to write
variable is less than the minimum value or more than the programs.
maximum value. Q. Differentiates between procedural programming language
An overflow occurs when the value assigned to a variable is and non-procedural programming language.
more than the maximum possible value .An underflow occurs PROCEDURAL LANGUAGE
when the value assigned value is less than the minimum value.
Procedural language are also known as third generation
For example, an integer variable can stored values from -32768 languages or 3GL. In procedural programming languages
to32767.If the assigned value is more than 32767, it is known as based upon concept of modular programming. Each module is a
integer overflow .But if the assigned vale is less than -32768 it is piece of code that implements a different functionality. There is
called underflow also a less possibility of errors in the programs. Some example
Q. what is ANSI C? are BASIC, FORTRAN, COBOL, PASCAL and C.

The American National Standard Institute (ANSI) developed a NON-PROCEDURAL LANGUAGE


standard version of the language. The standard version is known Procedural language are also known as fourth generation
as ANSI C. languages or 4GL. In non-procedural programming languages.
Q. what is meant by machine independence? In non-procedural language user only need tell the computer
PISK Computer Science GRADE 10 23

what to do. And how to do. There is also a less possibility of Language understand by computer is known as Low-level
errors in the programs. Some example are BASIC, FORTRAN, languages. These are machine language and assembly language.
COBOL, PASCAL and C. Machine language
Q. Differentiates between unstructured programming It is written in the form of 0 and 1. A program written in
language and structured programming language. machine language can be executed very fast by computer. The
In unstructured programming languages, the entire logic of computer does not need any translator to understand this
the program is implemented in a single module or function. The language.
programs written in these languages are error prone, difficult to Assembly language
understand, modify and debug.
Assembly language is a low-level language. It is one step higher
In structured programming languages, the entire logic of the than machine language. In assembly language, machine
program is divided into number of smaller modules or function. instructions are replaced with English-like words known as
Each module is a piece of code that implements a different mnemonics (like ADD, SUB).
functionality. There is also a less possibility of errors in the
2. High-level languages
programs. It consist of
Language near to human language is known as high-level
 Sequence
languages. The instructions in these languages are similar to
 Selection
English language such as input and print etc. These languages
 Repetition
are easy to understand. Common high-level languages are
 Object oriented language
C/C++, Java, Pascal, FORTRAN, BASIC, and COBOL.
Q. Explain different type of programming languages.
Q. Define source code and object code.
The languages understand by computer is known as
Source code
programming language. There are two types of computer
Source code is a computer program written in a high-level
programming languages (Low-level languages and high level).
programming language like C, C++, Visual Basic or Java. The
1. Low-level languages
source code cannot be executed by computer directly. It is
PISK Computer Science GRADE 10 24

converted into machine code and then executed. Example: program that print message “I Love Pakistan”.

Object code # include<stdio.h>


void main(void)
An object code is the program that is translated by a language
{
processor. It is also called machine code. Computer understands
printf("I Love Pakistan");
object code directly.
}
Q. List necessary steps taken to prepare a C program for
Q. what do you know about C statements?
execution.
A statement in C language is an instruction for the computer to
• Creating and Editing a C Program
perform a task. The statements are written in curly brackets.
• Saving a C Program Each statement in C is terminated with semicolon. The compiler
• Compiling a C Program generates an error if any statement is not terminated by semi

• Linking a C Program colon.

• executing a C Program Example: printf(“hello”);

Q. what is main function used in C programs?

A function is a block of code that performs a single task. The Q. define the term bug and debug.

main () function is the place where the execution of a C program An error in a computer program is known as bug. The
starts. When the program is executed, the control enters main () programmer can make different errors while writing programs.
function and starts executing its statements. Each program must The errors must be removed from the program before it can be
contain main () function. compiled and executed. The process of finding and removing

Syntax Void main() bugs is called debugging.

{ Q. explain different types of errors in C programs

Body of main function Different types of errors are syntax errors, logical errors and run-
time errors.
}
PISK Computer Science GRADE 10 25

Syntax error logical error.

Syntax error is a type of error that occurs when an invalid Q. what is main difference between low-level and high-level
statement is written in program. Syntax errors are detected by languages?
compiler. A program containing syntax errors cannot be High–level languages are easy and low-level languages are
compiled successfully. Typing 'forr' instead of for' is an example difficult. Low-level languages provide more hardware support
of syntax error. then high-level languages. The programs written in low-level
Logical errors languages are faster in execution.

A type of error that occurs due to poor logic of the programmer Q. what do you mean by delimiters?
is known as logical error. A statement with logical error may The statements of the programs are written in curly braces. The
produce unexpected and wrong results in the program. Typing a curly brace {is called opening brace and} is called closing brace.
wrong formula to calculate the result is an example of logic The braces are also known as delimiters. These statements are
error. collectively known as the body of a program.
Run-time errors Q. Why C is called middle level language?
A type of error that occurs during the execution of program is C is called middle level language because we can write
known as run-time error. It is caused when a statement directs instruction in high level language as well as in low level
the computer to execute an illegal operation such as dividing a language using C language.
number by zero.
Q. describe the characteristics of high-level programming
Q. Why is logical error the most difficult error? languages.
• It cannot be detected by the compiler. 1,Easy to learn:

• It does not crash the program. That is why it is difficult to High level languages are closer to human languages and far

detect. from machine language.

• The user needs to review the whole program to find out 2. Easy to error detection:

High level languages are easy to read and modify. it makes easy
PISK Computer Science GRADE 10 26

to find errors in programs written in high level languages. 70. It provided the basis for the development of C. the C
3. Standardized syntax: language was originally designed to write system programs

The syntaxes of high-level languages are standardized. These under UNIX operating system. The power and flexibility of C

languages describe a well-defined way of writing programs. made it popular industry for a wide range of application.

4. Deep hardware knowledge not required: The earlier version of C was known as K&R. The ANSI
developed a standard version of the language. It was known as
These languages do not require deep knowledge of hardware or
ANSI-C.
machine architecture. A programmer can write efficient
programs without a deep knowledge of hardware. Q. Briefly describe the basic structure of a C program.

5. Machine independence: The format of writing a program In C program is called


Structure. The basic structure of a C program is very flexible.
It means that the programs written in high level language can be
It increases the power of the language. It consists of the
executed on different types of computers.
following parts:
6. More programmers:
1. Preprocessor directive
Programming in low level language is difficult. But high level
1. Main( ) function
languages are easy to learn. It encourages more people to learn
2. Program body (C statements)
them..
7. Shorter programs: Example:

Programs written in high level languages are shorter than low Preprocessor directive #include<stdio.h>

level languages. Main function void main()


Q. Briefly describe the history of C language. Program body {
C is a popular high-level language. It was developed by
DENNIS RITCHIE at AT&T BELL LABORATORIES in 1972.
(C statements)
C language was derived from an earlier programming language
called B. The B was developed by KEN THOMPSON in 1969- }
PISK Computer Science GRADE 10 27

Q. Write the steps to prepare a program 6. Executing a C Program:

2. Creating and Editing a C program The process of running an executable file is known as
executing. The C++ program can be executed after compiling
The process of writing C program is known as editing. The
and linking. A program that places and executable file in the
process includes Writing, modifying and deleting program
memory is known as Loader. The program can be loaded
statements.
into memory by selecting Run > Run .
3. Saving a C Program:
The process of storing the program on disk is known as
Q, Write Components of System:
saving. A program should be saved on disk to be used
repeatedly. C programs are saved with .c extension. Following are different components of an information system:

4. Compiling a C Program ( ) 1.Hardware 2.Software 3.People / Users 4.Data / Information


5.Communication Setup
The process of converting source program into object
program is known as compiling. The program saved with .c Q. Explain scientific or exponential notation for floating

extension contains the statement of C language. It is known point number?

as source program. The source program cannot be executed The floating point number can also be written in an exponential
by computer directly. A compiler converts the source or scientific notation .This notation represents large floating
program into object program and save it in a separate file. point number in a short way.
The object program is saved with .obj extension. Exponential notation
5. Linking a C program: The notation consists of two parts
The process of linking library files with object program is
1. Mantissa
known as linking. These files are used to accomplish
different tasks such as input/output. A Library file must be 2. Exponent

linked with the object file before execution of program. A The general form of writing floating point values in exponential
program that combines the object program with additional notation is as follow +m e +n
library files is known as Linker. It is part of C++ compiler. The value before e is mantissa and the value after e is exponent.
PISK Computer Science GRADE 10 28

Some imp points about exponential form are

1. Mantissa and exponent maybe positive or negative value.

2. Exponents it is always an integer value .It cannot be in real


numbers.

0.00053= 5.3*10-4 =5.3e-4

Q Explain range and precision.

The possible values that a floating type variable can store are
described in terms of precision and range

Precision: It is a number of digits after decimal point

Range: This is the exponential power of 10.

A double variable has a precision of 15 digits and the range of


*10-308 to *10+308 .A large precision provides more accuracy .The
double data type is more suitable than float if the value to be
stored requires more precision.

Q. Define format specifier l.

l Format Specifier

Format l is used with as a prefix with %d, %f to convert it into


long data type like %ld and %lf. It is useful when computational
result is larger. %d or %f cannot hold that data.

Example

A=5000 B=5000

Product= a*b= 5000000 cannot be stored in int type.

You might also like