PRASAD V.
POTLURI SIDDHARTHA INSTITUTE OF TECHNOLOGY
DEPARTMENT OF MECHANICAL ENGINEERING
TWO MARKS QUESTION AND ANSWERS
UNIT-1
Introduction to Programming and Problem Solving
[Link] Question and answers
1 Define c?
Ans → C is a structured programming language
→ c was developed in 1970s by Dennis Ritchie at bell telephone
laboratories
2 What are the basic steps involved in writing a computer
program?
Writing of programs may involve the following steps:
1. Understanding the problem.
2. Planning the method of solution.
Ans
3. Development of the methods by using suitable algorithms,
flowcharts, etc.
4. Coding the instructions in a programming language.
5. Transforming the instructions into machine readable form (using an
input medium)
6. Program testing and debugging.
7. Documentation of the works involved in the production of the
program.
3 What is a computer program?
Ans A set of instructions written in one of the programming languages to solve
a problem is called a computer program.
4 What is an operating system?
Ans An operating system is a collection of programs used to connect the user
with the electronic hardware. The OS programs actuate and control the
activities of a computer
5 Define assemblers?
Ans An assembler is a computer program or translator which translates an
assembly language program into a machine language program.
6 What are compilers?
Ans → Compiler translates a source program, written in high-level
language into machine language. Compiler takes the whole program
at the input and check for errors. So, it is fast in the speed. Most of
the high-level languages are compiled language.
→ One of the features of the compiler that, it will convert the source
program in the object program. So, every time no need of source
program
7 What are interpreters?
Ans Interpreter translates each statement of the source program into a
sequence of machine level instructions. Interpreters takes the input line by
line and check for the errors. So, it is slower than compiler. Interpreter
always need the source program every time.
8 Define identifier
Ans Identifiers are symbols used to uniquely identify a program element in the
code. They are also used to refer to types, constants, and parameters.
Or
An identifier is the name given to program elements such as variables,
functions, and arrays, etc. Identifiers are also the names of objects, which
can take different values but only one value at a time.
Example: The following names are valid identifiers:
X , y12, sum_1 , _temperature, names , area ,
tax_rate, TABLE
9 Define keyword.
Ans → Keywords are predefined; reserved words used in programming that
have special meanings to the compiler.
→ Keywords are part of the syntax, and they cannot be used as an
identifier.
→ Ex: auto, break, case, char, do, default
10 Write any two preprocessor directives in C
Ans Preprocessor directive instructions are used to instruct the preprocessor
to expand/translate the source program before compilation The two types
of preprocessor directives are,
#define to define Macro, Global constant
#include to include library files
11 what are character set?
Ans 1. letters
2. digits
3. special characters
4. white space
12 What is the importance of keywords in C?
Ans → Keywords are reserved identifiers.
→ They perform a specific task, specifies the data type
→ Keyword cannot be used as an identifier.
→ Ex: for, if, int
13 What do you understand by compilation and execution of a program?
Ans Compilation:
→ To translate the entire source code of a program from a high-level
language into object code prior to execution of the program is
known as compilation.
→ A program that performs this task is known as compiler.
Execution:
→ When the object code made after compilation, the object code is
linked with other library code, which are needed for execution of
the program.
→ The resulting code is known as executable code.
14 Define Testing and Debugging
Ans Testing: Testing is the process in which a program is validated.
Debugging: Debugging is a process in which program errors are removed.
15 List the rules of naming an identifier in C
Ans (i) An identifier must start with a letter or underscore followed by
any number of digits and/or letters.
(ii) No reserved word or standard identifier should be used.
(iii) No special character (other than underscore) should be included
in the identifier
16 Define Variables
Ans → A variable is a name given to a storage area that our programs can
manipulate.
→ Each variable in C has a specific type which determines the size
and layout of the variable’s memory.
Or
→ A variable is a name that C language compiler associates with a
storage location in the main memory of the computer
17 How to declare Variables?
Ans → A variable declaration provides assurance to the compiler that there
exists a variable with the given type and name so that the compiler
can proceed for further compilation without requiring the complete
detail about the variable.
→ Syntax: Data type Variable name;
18 What is meant by expressions?
Ans An expression is any legal combination of symbols that represent a value.
Each expression consists of at least one operand and can have one or
more operators.
19 Define Statements?
Ans → Computer that instructs the computer to take a specific action,
such as display to the screen, or collect input.
→ A computer program is made up of a series of statements
20 How can the values of an expression be converted to a different data
type?
Ans The value of an expression can be converted to a different data type if
desired. To do so, the expression must be preceded by the name of the
desired data type, enclosed in parentheses.
i.e (data type) expression
This type of construction is known as a cast.
21 Define c tokens? What are it types
Ans The smallest individual units are known as c tokens.
C has six types of tokens
1. Identifiers:
2. Keywords
3. Constants
4. Strings
5. Special Symbols
6. Operators
22 define void:
Ans Void is an empty data type. It returns nothing. The void type has no
value.
23 What is meant by constants?
Ans → Constants are also like normal variables. But only difference is
their values cannot be modified by the program once they are
defined.
→ Constants refer to fixed values.
→ They are also called as literals
→
24 define data type and their types:
Ans C language is rich in its data type. There are four types:
1. Primary or fundamental data type
2. Derived data type
3. User defined data type
4. Empty data type
25 define scanf () function:
Ans Scanf () function is used to read the value from the input device
26 define printf () function:
Ans Printf () function is used to display data on the monitor.
27 Define type conversion:
Ans The operands are different types in the expression. The lower type is
automatically converted to the higher type before the operation proceeds.
28 Define type caste Operators:
Ans The process of such local conversion of variable is known as casting value
or type modifier or type caste operator
29 what is called associativity?
Ans If two operators with the same precedence occur in an expression. The
order in which they are executed is called associativity
30 Differentiate between syntax errors and run-time error
Ans Syntax error messages:
→ Syntax error or compilation errors are detected and displayed by
the compiler as it attempts to translate our program.
→ If a statement has a syntax error, it cannot be translated, and our
program will not be executed.
Runtime error messages:
→ Run time errors are detected by the computer and are displayed
during execution of a program.
→ A run-time error occurs when the program directs the computer to
perform an illegal operation, such as dividing a number by zero.
31 What is meant by operators?
Ans An operator is a symbol that tells the compiler to perform specific
mathematical or logical functions.
Or
An operator is a symbol that is to perform mathematical or logical
manipulation. It is used in program to manipulate data and variables
32 Define Arithmetic operator.
Ans → An arithmetic operator performs mathematical operations such as
addition, subtraction, and multiplication on numerical values.
Ex: +, -, *, /, %
33 Define logical operator.
Ans → An expression containing logical operator returns either 0 or 1
depending upon whether expression results true or false.
→ Logical operators are commonly used in decision making in C
programming.
Ex: && ||!
34 Define Assignment operator
Ans → An assignment operator is used for assigning a value to a variable.
The most common assignment operator is =
→ Ex: = =+ -= *= /= %=
35 Define Conditional operator
Ans → A conditional operator is a ternary operator that is it works on 3
operands.
Syntax: Conditional Expression? expression1: expression2
36 Differentiate between compile-time and run-time errors giving proper
examples of each
Ans → A compile-time error is an error that occurs when a program is
being compiled.
→ Examples: syntax errors such as omitting a required semicolon,
using an undeclared variable, using a keyword for the name of a
variable
→ A run-time error is an error that occurs when a program is
running. Numeric overflow and division by zero are examples of
run-time errors.
37 What is top-down design?
Ans Top-down design is the technique of breaking down a problem into
various major tasks needed to be performed.
38 Define constant and mention their types?
Ans The constant is a value, written into a program instruction that does not
change during the execution of a program.
There are four basic types of constants in C. They are integer constants,
floating-point constants, character constants and string constants.
39 Define Integer constants?
Ans → An integer constant is an integer–valued number.
→ Thus, it consists of a sequence of digits.
→ Integer constants can be written in three different systems: decimal
(base 10), octal (base 8) and hexadecimal (base 16).
40 Define Floating-Point Constants?
Ans → A floating-point constant is a base-10 number that contains either
a decimal point or an exponent (or both)
→ Example: Several valid floating-point constants are shown
below:
→ 0,1,0.2, 827.602, 50000, 0.000743 ,12.3 2E-8, 0.006e-3,
1.6667E+8
41 Define Character Constants?
Ans → A character constant is a single character, enclosed in single
quotation marks.
→ Example: Several character constants are shown below:
“A‟, ” b‟, ”3‟
42 Define String Constants?
Ans → A string constant consists of any number of consecutive characters,
enclosed in double quotation marks.
→ Example: Several string constants are shown below:
“green” “Washington, D.C. 20005”, “$19.95”
43 State the differences between compiler and interpreter.
Ans Compiler Interpreter
1 Scans the entire Translates the program line by line
program first and then
translates it into
machine code
2 Converts the entire Each time the program is executed,
program to machine every line is checked for syntax error
code; when all the and then converted to equivalent
syntax errors are machine code.
removed execution takes
place
3. Slow for debugging Good for fast debugging
4. Execution time is less Execution time is more
44 What are the properties of Algorithm?
Ans → Finiteness: - An algorithm terminates after a finite number of steps.
→ Definiteness: - Each step in algorithm is unambiguous. This
means that the action specified by the step cannot be interpreted
(explain the meaning of) in multiple ways & can be performed
without any confusion.
→ Input: - An algorithm accepts zero or more inputs
→ Output: - An algorithm should produce at least one output.
→ Effectiveness: - It consists of basic instructions that are realizable.
This means that the instructions can be performed by using the
given inputs in a finite amount of time
45 Define Flowchart? and what are its uses?
Ans The pictorial representation of algorithm is called flowchart.
Uses of flow chart:
→ flow chart helps to understand the program easily.
→ as different symbols are used to specify the type of operation
performed, it is easier to understand the complex programs with
the help of flowchart
46 Mention the General Structure of a C program?
Ans /* Documentation section */
/* Link section */
/* Definition section */
/* Global declaration section */
main ()
{
Declaration part Executable part (statements)
}
/* Sub-program section */
47 List out various Input & output statements in C
Ans The input & output statements are classified into formatted &
unformatted IO.
Formatted I/O: User can be able to design/format the output.
Unformatted I/O: doesn’t ‘t allow the users to design the output
48 Show the Usual Arithmetic Conversion
Ans
49. What are the features of c programming?
1. High-level programming language.
2. Small language having only 32 keywords.
3. Core language as many other programming languages are dependent on C.
4. portable language
5. Has built in functions and operators
6. structured language / It supports Modular programming
7. Supports use of Pointers.
8. Compilation and execution is faster
9. Case sensitive
10. Dynamic memory allocation
50. Define primary and secondary memory.
1. Primary memory (Main memory)
▪ Primary memory is the storage area that is directly accessible by the CPU at very high
speed.
▪ Temporary storage.
▪ The capacity of primary memory is limited and also, we can’t store the data
permanently.
✓ Ex: RAM (Random access memory), ROM (Read only memory)
2. Secondary memory (Auxiliary memory)
▪ Secondary memory is used to store the data permanently.
▪ The capacity of secondary memory is high and low cost.
✓ Ex: Hard disc, Floppy, CD/DVD etc.
51. What are various types of the programming languages?
• Low Level Language
• High Level Language
o Machine Language
o Assembly Language
52. Write in detail about the Generation of Programming Languages.
There are five generations of Programming languages. They are:
▪ First-Generation Languages :
These are low-level languages like machine language.
▪ Second-Generation Languages :
These are low-level assembly languages used in kernels and hardware drives.
▪ Third-Generation Languages :
These are high-level languages like C, C++, Java, Visual Basic, and JavaScript.
▪ Fourth Generation Languages :
These are languages that consist of statements that are similar to statements in the
human language. These are used mainly in database programming and scripting.
Examples of these languages include Perl, Python, Ruby, SQL, and MatLab
(MatrixLaboratory).
▪ Fifth Generation Languages :
These are the programming languages that have visual tools to develop a program.
Examples of fifth-generation languages include Mercury, OPS5, and Prolog.
53. Write the Characteristics of the computer system.
54. What are the various generations in computers?
Generation Time Period Technology Used
1st Generation 1940s – 1950s Vacuum Tube Based
2nd Generation 1950s – 1960s Transistor Based
3rd Generation 1960s – 1970s Integrated Circuit Based
4th Generation 1970s – Present Microprocessor Based
5th Generation Present – Future Artificial Intelligence Based
55. What is problem solving? And what are the different types of problem solving techniques?
Problem solving is the process of solving a problem in a computer system by following a
sequence of steps.
➢ Developing an Algorithm
➢ Drawing the Flowchart
➢ Writing the Pseudocode
56. What are the various files used in computer system?
1. Source File (sample.c)
2. Header Files (.h)
3. Object File ([Link])
4. Executable File ([Link])
57. Write different types of an operator.
➢ Arithmetic Operators.
➢ Relational Operators.
➢ Logical Operators.
➢ Assignment Operators.
➢ Increment or Decrement Operators.
➢ Conditional Operators.
➢ Bitwise Operators.
➢ Special Operators.
58. Explain Top-down approach.
➢ In this approach we focus on breaking up the big program into smaller program.
➢ If the sub program is difficult, further we will break into smaller program.
➢ Mainly this is used by structured programming languages like C, Fortan, COBOL etc.
59. Explain Bottom-up approach.
➢ In bottom-up approach we will create small problems first, then we will solve the smaller
problems.
➢ Then we will integrate all the small problems into a whole and complete the solution.
➢ Mainly used by object-oriented programming like C++, Java, Python etc.
60. Define Time complexity.
Time complexity is a type of computational complexity that describes the time required to
execute an algorithm. The time complexity of an algorithm is the amount of time it takes for
each statement to complete. As a result, it is highly dependent on the size of the processed data.
61. Define space complexity.
Space complexity refers to the total amount of memory space used by an algorithm/program,
including the space of input values for execution. Calculate the space occupied by variables in
an algorithm/program to determine space complexity.