Notes

10th Computer Notes Chapter 2

10th Computer Notes Chapter 2

Chapter 2: Programming in C

Write short answers to the following questions.

i. Define computer programs.

Ans. A computer program is a set of instructions (statements) written in a programming language to solve a particular problem and achieve specific results. Each statement of a programming language has syntax and semantics.

ii. Differentiate between syntax and semantics.

Ans.

Syntax

Syntax refers to the rules of a programming language according to which statements of a program are to be written. It describes the way to write correct statements in a program.

Semantic

Semantic gives meaning to statements of a programming language. It describes the sequence of operations to be performed by a computer when executing the statements of a computer program.

iii. Write three differences between assembly language and HLLs.

Ans

  • Assembly language consists of symbolic codes or abbreviations known as mnemonics. High-level languages are English-oriented languages and they are commonly used for writing computer programs.
  • Assembly language allows programmers to have access to all the special features of the computer they are using. Certain types of operations are not possible in high-level languages.
  • Generally, a program written in assembly language will require less storage and less running time than one prepared in a high-level language.

iv. Write four characteristics of HLLs.

Ans: High-level languages have the following characteristics.

  1. These languages were developed to make computer programming simple, easier, and less prone to errors.
  2. High-Level languages are not machine-dependent. They enable programmers to write programs that are Independent of a particular type of computer.
  3. Programs written in high-level languages must be translated into machine language by a compiler or an interpreter before execution by the computer.
  4. The process of finding and removing errors in programs (debugging) is easier in high-level languages compared to low-level languages.

v. Define Integrated Development Environment (IDE).

Ans. INTEGRATED DEVELOPMENT ENVIRONMENT

An Integrated Development Environment (IDE) is used to create, compile and run programs. IDE is computer software that brings all the processes and tools required for program development into one place. IDE’s aim is to make the lives of programmers easier by grouping together all the tasks needed for building applications into one environment.

vi. Differentiate between constant and variable.

Ans. Constants are quantities whose values do not change during program execution. They may be numeric, character, or string.

A variable is a symbolic name that represents a value that can change during a program. A variable has a name, known as the variable name and it holds data of other numbers or any other type of data held in a variable is called its value. 

vii. Which of the following are valid C variables? Give the reason if not a valid variable.

area, 5x, Sum, net pay, float, _age, else, case, size22, my_weight

Ans: The following are the valid C variables:

                Area, Sum, _age, size22, my_weight

The following are not valid C variables:

                5x                           cannot begin with a digit

                net pay                 Blank Space is not allowed

                float                       cannot use reserve word

                else                        cannot use reserve word

                case                       cannot use reserve word

viii. What are reserved words? Why they should not be used as variable names?

Ans. The words that are part of programming language and have special purposes in computer programs are called reserved words or keywords. They have predefined uses and cannot be used for any other purpose. Reserved words are always written in lowercase. There are 32 words defined as reserved words in C.

ix. Why comments are used in programs?

Ans. It is good programming practice to add comments to the program to make it easy for others to understand it. Comments in the source code are ignored by the compiler. Comments are added in programs when a fact is necessary to be brought to the attention of the program’s reader.

x. What is the purpose of header files in C language?

Ans: C language contains a number of standard functions in library files that perform various tasks in C programs. These tasks include all the input/output operations and all the main operations. Library file contains header files and each header file contains a set of functions. Some commonly used header files are stdio.h, conio.h and math.h.

Extensive Questions

Q1. Describe the following HLLs.

  1. a) C/C++  b) Visual Basic                  c) C#                      d) Java

C/C++

C language was developed in the early 1970s by Dennis Ritchie at Bell Laboratories become one of the most popular programming languages today. It is a highly structured programming language that is easy to understand and use. 

C++ was developed by Bjarne Stroustrup also at Bell Laboratories during 1 983-1985. C++ is a superset of C, meaning that any valid c program is also a valid C++ program. The purpose of developing C++ was to provide programming facilities to easily and quickly write more powerful programs.

Visual Basic

Visual Basic (VB) is a high-level language that evolved from the earlier version called BASIC. BASIC stands for Beginner’s: All-purpose Symbolic Instruction Code. VB Is a Very popular programming language for writing Windows and Web applications. 

C#

C# (pronounced as C-sharp) is a language developed in 2000 by Microsoft Corporation. It is a simple, modern, general-purpose programming language. The syntax of C# is very similar to C and C++. It also has some features of Java. It is a language that makes computer programming easy and efficient.

Java

Java is a high-level language developed by Sun Microsystems. It is very similar in syntax to C and C++. In Java, the user can write all types of programs as those written in other programming languages and small programs that can be embedded in a Web page accessed through the Internet. Java is an ideal language for network computing. 

Q2. What is C language IDE? Explain its modules in detail.

Ans: IDE

An Integrated Development Environment (IDE) is used to create, compile and run programs. IDE is computer software that brings all the processes and tools required for program development into one place. IDE’s aim is to make the life of programmers easier by grouping together all the tasks needed for building applications into one environment.

Modules of IDE:

A C language IDE consists of the following modules

  • Text Editor
  • Compiler
  • Linker
  • Loader
  • Debugger

Text Editor

A text editor is a simple word processor that is used to create and edit the source code of a program. Files created by a text editor are plain text files. Most editors automatically highlight compile errors by simply removing them.

Compiler

A compiler is computer software that translates a source program into an object program. The source program consists of statements written in a high-level language. When a source program is translated with a compiler into machine language, the resulting program is known as an object program. 

Linker

A linker is software that translates an object program into a single executable program. During this process, if it couldn’t find the definition of a particular function used in the program, then it would assume that it is defined in the C library. It will replace this function in the object program with the code from the C library and then create a single executable program.

Loader

It is software that loads programs into memory and then executes them.

Debugger

It is software that executes a program line by line, examines the values stored in variables, and helps find and remove errors in the program.

Q3. What are the rules for specifying a variable name in C language?

Ans. RULES FOR SPECIFYING VARIABLE NAMES

The following are the rules for specifying variable names in C language. 

  • A variable begins with a letter or underscore (_) and may consist of letters or digits.
  • The underscore may be used to improve the readability of the variable name over time.
  • There is no restriction on the length of a variable name. However, only the first 31 characters of a variable are significant.
  • Both upper and lower case letters are allowed in naming variables. An upper-case letter is considered different from a lower-case letter. For example, the variable AVG is different from Avg or avg.
  • Special characters cannot be used as variable names: e.g., #,?, @ etc.
  • Reserved words of C language such as int, case, if, etc., cannot be used as variable names.
  • There must be no embedded blank in the name of the variable. For example “ma ss” is not correct.

Q4. What is a pre-processor directive? Explain #include pre-processor directive in detail.

Ans:

Pre-processor directive

Pre-processor directives are instructions for the C compiler. Every C language program contains certain pre-processor directives at the beginning of the program. Before translating a C language program into machine language, the compiler of C language carries out the processor directives. These directives start with the number sign (#). The most commonly used pre-processor directives are #include and #define.

#include Pre-Processor Directive

It has the following syntax:

#include<header file name>

When the C compiler runs the pre-processor, it looks for the header file inside the less than (<) and greater than (>) symbols and copies it into the source file.

Q.5 Differentiate between compiler and interpreter.

Compiler

A compiler is computer software that translates a source program into an object program. The source program consists of statements written in a high-level language. When a source program is translated with a compiler into machine language, the resulting program is known as an object program.

Interpreter

An interpreter translates high-level language programs into machine language but it translates one instruction at a time and executes it immediately before translating the next instruction. Examples of programming languages that use interpreters are JavaScript, BASIC, Visual Basic, and Perl.

An interpreter reads each statement of the source program one at a time. It means each time a statement is read, it must be translated into machine language before execution. A compiler translates the entire program into an object program before execution by a computer. Therefore, a compiled program runs fast.

Select the best answer for the following MCQs.

 i. What defines the rules of valid statements in programming?

A. Compiler

B. Interpreter

C. Syntax                                                    

D. Semantic

ii. Which language is directly understood by the computer?

A. Machine language 

B. Assembly language

C. High-level language                                  

D. C language

iii. When was C language developed?

A. Late 1960s 

B. Early 1970s

C. 1980s 

D. 1990s

iv. Who developed Java language?

A. Dennis Ritchie                                          

B. Microsoft  

C. Sun Microsystems 

D. IBM

v. What is the other word used for Reserved Words?

A. Compiler words 

B. Keywords

C. Special programming words 

D. Mnemonics

vi. How many bytes are set aside by the compiler for a variable of type int?

A. 2                                                                

B. 3

C. 4                                                                  

D. 5

vii. How many bytes are set aside by the compiler for a variable of type float?

A. 2 

B. 3

C. 4                                                                  

D. 5

viii. What is the range of numbers that can be stored in a variable of type double float?

A. -32,768 ~ +32 767 

B. 10-38 ~ 1038

C. 10-308~ 10308                                              

D. 10-4932 ~ 104932

ix. Which program translates high-level language into machine language?

A. Compiler                                                 

B. Linker

C. Loader 

D. Debugger

x. Which software helps in finding and removing errors in programs?

A. linker 

B. Text Editor

C. Loader 

D. Debugger

Download 10th Computer Chapter 2 Notes in pdf

Next: Chapter 3: Input and Output Handling

Muhammad Hussain

Recent Posts

Unit 8: Entrepreneurship in Digital Age

Unit 8: Entrepreneurship in Digital Age Write answers of the following short response questions. Q.1.…

1 month ago

Unit 7: Digital Literacy

Unit 7: Digital Literacy Write answers of the following short response questions. Q.1. Differentiate between…

1 month ago

Unit 6: Impacts of Computing

Unit 6: Impacts of Computing Write answers to the following short response questions. Q1. List…

1 month ago

Unit 5: Applications of Computer Science

Unit 5: Applications of Computer Science Write answers of the following short response questions. Q1.…

2 months ago

Unit 4: Data and Analysis

10th Computer Science Unit 4 Data and Analysis Write answers of the following short response…

3 months ago

Unit 3: Programming Fundamentals

10th Computer Unit 3: Programming Fundamentals Unit 3: Programming Fundamentals Write answers of the following…

3 months ago