IPLC Theory Exam Question & Answers
2 question answer are coming soon :
1. Explain Machine level language with all its limitations.ANS)
Machine Language :
Machine Language is the only language that is directly understood by the computer. It does not needs any translator program. When this sequence of codes is fed to the computer, it recognizes the codes and converts it in to electrical signals needed to run it. We also call it machine code and it is written as strings of 1's (one) and 0’s (zero). For example, a program instruction may look like this:
1011000111101
It is considered to the first generation language. It is efficient for the computer but very inefficient for programmers. It is not an easy language for programmer to learn because of its difficult to understand. It is also difficult to debug the program written in this language.
The only advantage is that program of machine language run very fast because no translation program is required for the CPU.
Disadvantages Machine Language:
- It is very difficult to write program in machine language. The programmer has to know details of hardware.
- The programmer has to remember a lot of codes to write a program which results in program errors.
- It is difficult to debug the program.
2. Explain Assembly language with all its limitations.ANS)
Assembly Language :
It is the first step to improve the programming structure. You should know that computer can handle numbers and letter. Therefore some combination of letters can be used to substitute for number of machine codes.
The set of symbols and letters forms the Assembly Language and a translator program is required to translate the Assembly Language to machine language. This translator program is called `Assembler'. It is considered to be a second-generation language.
The symbolic programming of Assembly Language is easier to understand and saves a lot of time and effort of the programmer. It is easier to correct errors and modify program instructions.
Disadvantages Assembly Language:
- One of the major disadvantages is that assembly language is machine dependent. A program written for one computer might not run in other computers with different hardware configuration.
3. Explain High level language with all its limitations.
ANS)
High level language is abbreviated as HLL. High level languages are similar to the human language. Unlike low level languages, high level languages are programmers friendly, easy to code, debug and maintain.
HHL do not interact directly with the hardware. Rather, they focus more on the complex arithmetic operations, efficiency and easiness in coding.
High level programs require compilers/interpreters to translate source code to machine language. We can compile the source code written in high level language to multiple machine languages. Thus, they are machine independent language.
Limitation of High level language :
It takes additional translation times to translate the source to machine code.
High level programs are comparatively slower than low level programs.
Compared to low level programs, they are generally less memory efficient.
Cannot communicate directly with the hardware.
4. Write an algorithm to input a number and display factorial of that number
ANS)
5. Write an algorithm to input a number and display a message whether Number is Armstrong or not
ANS)
6. Write features of High level language. Differentiate Assembly language and High level language.ANS)
Feature of high level language :
- High level languages are programmer friendly.
- They are easy to write, debug and maintain.
- It provide higher level of abstraction from machine languages.
- It is machine independent language.
- Easy to learn.
- Less error prone, easy to find and debug errors.
- High level programming results in better programming productivity.
- In assembly language programs written for one processor will not run on another type of processor. In high-level language programs run independently of processor type.
- Performance and accuracy of assembly language code are better than a high-level.
- Code of assembly language is difficult to understand and debug than a high-level.
- One or two statements of high-level language expand into many assembly language codes.
- Assembly language can communicate better than a high-level Some type of hardware actions can only be performed by assembly language.
- Working with bits is easier in assembly language.
- Assembler is used to translate code in assembly language while the compiler is used to compile code in the high-level.
- The executable code of high-level language is larger than assembly language code so it takes a longer time to execute.
- Due to long executable code, high-level programs are less efficient than assembly language programs.
- Examples of assembly language:
ARM, MIPS, x86, Z80
- Examples of high-level language:
C, Fortran, Basic, C++, C#, PHP, Ruby, Python, Javascript.
7. Write an algorithm to generate fibonnacci series.ANS)
8. Explain Basic structure of 'C' program.
ANS)
Basic structure of C
Documentation section: The documentation section consists of a set of comment lines giving the name of the program, the author and other details, which the programmer would like to use later.
Link section: The link section provides instructions to the compiler to link functions from the system library such as using the #include directive.
Definition section: The definition section defines all symbolic constants such using the #define directive.
Global declaration section: There are some variables that are used in more than one function. Such variables are called global variables and are declared in the global declaration section that is outside of all the functions. This section also declares all the user-defined functions.
Main () function section: Every C program must have one main function section. This section contains two parts; declaration part and executable part
Declaration part: The declaration part declares all the variables used in the executable part.
Executable part: There is at least one statement in the executable part. These two parts must appear between the opening and closing braces. The program execution begins at the opening brace and ends at the closing brace. The closing brace of the main function is the logical end of the program. All statements in the declaration and executable part end with a semicolon.
Subprogram section: If the program is a multi-function program then the subprogram section contains all the user-defined functions that are called in the main () function. User-defined functions are generally placed immediately after the main () function, although they may appear in any order.
All section, except the main () function section may be absent when they are not required.
9. Explain logical operators in 'C' language.
ANS)
Logical Operators:They are used to combine two or more conditions/constraints or to complement the evaluation of the original condition under consideration. They are described below:
Logical AND operator: The ‘&&’ operator returns true when both the conditions under consideration are satisfied. Otherwise it returns false. For example, a && b returns true when both a and b are true (i.e. non-zero).
Logical OR operator: The ‘||’ operator returns true even if one (or both) of the conditions under consideration is satisfied. Otherwise it returns false. For example, a || b returns true if one of a or b or both are true (i.e. non-zero). Of course, it returns true when both a and b are true.
Logical NOT operator: The ‘!’ operator returns true the condition in consideration is not satisfied.
Otherwise it returns false. For example, !a returns true if a is false, i.e. when a=0.
10. Write different syntaxes of if conditional statement.
ANS)
11. Explain unary operators available in 'C' language.
ANS)
Unary operators :
C programming has two operators increment ++ and decrement -- to change the value of an operand (constant or variable) by 1.Unary operators also called as increment and decrement operator.
C Increment and Decrement Operators Increment ++ increases the value by 1 whereas decrement -- decreases the value by 1. These two operators are unary operators, meaning they only operate on a single operand.
C programming has two operators increment ++ and decrement -- to change the value of an operand (constant or variable) by 1.Unary operators also called as increment and decrement operator.
C Increment and Decrement Operators Increment ++ increases the value by 1 whereas decrement -- decreases the value by 1. These two operators are unary operators, meaning they only operate on a single operand.
Example :
#include <stdio.h>
void main()
{
int a = 10, b = 100;
cltrscr();
printf("++a = %d \n", ++a);
printf("--b = %d \n", --b);
gtech();
}
Output :
++a = 11
--b = 99
12. Differentiate between entry controlled loop and exit controlled loop.
ANS)
13. Differentiate between break and continue statement.
ANS)
14. Write an algorithm to input 2 numbers and display largest number.
ANS)
15. Explain While loop , for loop and do..while loop with an example each.
ANS)
While loop
Reports a standard or group of statement while a given condition is true it tests the condition before executing the loop body.
It tests the condition before executing the loop body
Example :
#include<stdio.h>
Main()
{
Int no=1;
Clrscr();
While(no>=10)
{
Printf(“\n %d ”,no);
No=no+1;
}
Getch();
}
Output :
12345
For loop:
It is also entry controlled loop means checks the conditiom first if condition is true than execute the code inside the loop.
Example :
include<stdio.h>
main()
{
int no=1
clrscr();
for(no=0;no>=5;no++)
{
printf(“\n %d ”,no);
printf(“\n %d ”,no);
}
getch();
getch();
}
Output :
12345
Do...while loop :
Do...while loop is exit controlled loop it checks condition at the end of iteration . it will execute atleast one time.
Example :
include<stdio.h>
main()
{
{
int
clrscr();
do
do
{
printf(“%d”,no);
no=no+1;
}while(no<=5);
getch();
}
OUTPUT:
12345
16. Explain nested If with syntax.
ANS)
Nested-if in :
A nested if in C is an if statement that is the target of another if statement. Nested if statements means an if statement inside another if statement. C allows us to nested if statements within if statements, i.e, we can place an if statement inside another if statement.
Syntax:
if (condition1)
{
// Executes when condition1 is true
if (condition2)
{
// Executes when condition2 is true
}
}
Example :
#include <stdio.h>
int main()
{
int a = 47, b = 25, c = 3;
clrscr();
if (a > b)
{
if (a > c)
{
printf("The value a is greater than b and c ");
}
}
printf("\nThis is normal flow ");
getch();
}
OUTPUT :
The value is greater than b and c
When the first if statement executed, the value 'a' is compared with value 'b', if the expression is true, then inner if statement executed, the inner expression compares the value a with value c, if the inner if statement also true, the compiler will display the output.
A nested if in C is an if statement that is the target of another if statement. Nested if statements means an if statement inside another if statement. C allows us to nested if statements within if statements, i.e, we can place an if statement inside another if statement.
Syntax:
if (condition1)
{
// Executes when condition1 is true
if (condition2)
{
// Executes when condition2 is true
}
}
Example :
#include <stdio.h>
int main()
{
int a = 47, b = 25, c = 3;
clrscr();
if (a > b)
{
if (a > c)
{
printf("The value a is greater than b and c ");
}
}
printf("\nThis is normal flow ");
getch();
}
OUTPUT :
The value is greater than b and c
When the first if statement executed, the value 'a' is compared with value 'b', if the expression is true, then inner if statement executed, the inner expression compares the value a with value c, if the inner if statement also true, the compiler will display the output.
17. Write an algorithm to input 2 numbers and display smallest number.
ANS)
18. Explain nested loop with syntax.
ANS)
A loop within another loop is called nested loop. This is how a nested loop looks like:
Outer-Loop
{
// body of outer-loop
Inner-Loop
{
// body of inner-loop
}
... ... ...
}
Outer loop encloses the inner loop. The inner loop is a part of the outer loop and must start and finish within the body of outer loop.
On each iteration of outer loop, the inner loop is executed completely.
Syntax :
Outer-Loop
{
// body of outer-loop
Inner-Loop
{
// body of inner-loop
}
... ... ...
}
Outer loop encloses the inner loop. The inner loop is a part of the outer loop and must start and finish within the body of outer loop.
On each iteration of outer loop, the inner loop is executed completely.
Syntax :
for (int i=0; i<5; i++)
{
// body of outer for loop
for (int j=0; j<5; j++)
{
// body of inner for loop
}
// body of outer for loop
}
{
// body of outer for loop
for (int j=0; j<5; j++)
{
// body of inner for loop
}
// body of outer for loop
}
Nice
ReplyDelete