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

PPS Module wise questions:

Module 1:-
1. What is computer? Draw a and discuss it’s components.
A computer is a device that accepts information (in the form of digitalized data) and manipulates it for some
result based on a program, software, or sequence of instructions on how the data is to be processed.

Input – Input unit connects the user to the computer by taking data from user and converting it to
machine readable form and transmit this data to the main memory of the computer.
CPU - Central Processing Unit or the CPU, is the brain of the computer. The CPU comprises of two units,
namely – ALU (Arithmetic Logic Unit) and CU (Control Unit).

ALU - The Arithmetic Logic Unit is made of two terms, arithmetic and logic. There are two primary functions
that this unit performs.

1. Data is inserted through the input unit into the primary memory. Performs the basic
arithmetical operation on it. Like addition, subtraction, multiplication, and division. It performs
all sorts of calculations required on the data. Then sends back data to the storage.
2. The unit is also responsible for performing logical operations like AND, OR, Equal to, Less
than, etc. In addition to this it conducts merging, sorting, and selection of the given data.

CU- The control unit as the name suggests is the controller of all the activities/tasks and operations. All this
is performed inside the computer.

Memory unit- Two types of computer memory:

Primary memory – Also called temporary memory. It is only used to store recent data. The data
stored in this is temporary. It can get erased once the power is switched off. RAM is an example of
primary memory.
Secondary memory - Also called permanent memory. The hard disk is an example of secondary
memory. Even in a power failure data does not get erased easily.
Output unit- The output unit accepts the data in binary form from the computer. It then converts it
into a readable form for the user.
2. What is algorithm? Discuss it’s characteristics and write an algorithm to find out the
largest number among three given numbers.

The word Algorithm means ” A set of finite rules or instructions to be followed in calculations or
other problem-solving operations ”
The algorithm should be unambiguous. Each of its steps should be clear in all aspects and must lead to only one meaning. it should
be well-defined inputs. It may or may not take input. The algorithm must clearly define what output will be yielded and it should be
well-defined as well. The algorithm must be finite, i.e. it should
terminate after a finite time. The algorithm must be simple, generic,
and practical. The Algorithm designed must be language-
independent, i.e. it must be just plain instructions that can be
implemented in any language.

Algorithm to find out largest of three numbers:

1. Start

2. Add values to A, B, and C for comparison.

3. Check whether A is Greater than B.

• If it is true, see if A is greater than C.

• If it is true, print ‘A’ as the greatest number.

• ‘C’ will be printed as the greatest number if false.

• If that is false, check if B is greater than C.

• If it is true, print ‘B’ as the highest number.

• ‘C’ will be printed as the greatest number if false.

4. End

3. What is flowchart? Discuss the different types of geometrical figures used in flowchart.
Draw a flowchart to find out the root of quadratic equation.
OR
Print the Fibonacci series.

A flowchart is a type of diagram that represents a workflow or process. A flowchart can also be
defined as a diagrammatic representation of an algorithm, a step-by-step approach to solving a
task.

This box is of an the main This is a Diamond-shaped This arrow line This circular figure
oval shape which processing codes parallelogram- box-control represents the is used to depict
is used to indicate is written inside shaped box statements like if, flow of the that the flowchart
the start or end of this box. inside which condition like a > algorithm or is in continuation
the program. Every the inputs or 0, etc are written process. It with the further
flowchart diagram outputs are inside this box. represents the steps. This figure
has an oval shape. written. direction of the comes into use
process flow. when the space is
less and the
flowchart is long.
4. Draw a Flowchart to print “Hello” 7 times.

5. Write down about Assembler, Compiler and Operator along with their difference.

A language processor is a computer program that convert source code from programming
language to human readable language. They are of three types :
• Assembler- The Assembler is used to translate the program written in Assembly language
into machine code.
• Compiler- The language processor that reads the complete source program written in high-
level language as a whole in one go and translates it into an equivalent program in machine
language is called a Compiler. Example: C, C++, C#.
• Interpreter- The translation of a single statement of the source program into machine code is
done by a language processor and executes immediately before moving on to the next line is
called an interpreter.

Compiler Interpreter

A compiler is a program that converts the entire source code of An interpreter takes a source program and runs it line by line,
a programming language into executable machine code for a CPU. translating each line as it comes to it.

The compiler takes a large amount of time to analyze the entire source
An interpreter takes less amount of time to analyze the source
code but the overall execution time of the program is comparatively
code but the overall execution time of the program is slower.
faster.

The compiler generates the error message only after scanning the whole Its Debugging is easier as it continues translating the program
program. until the error is met.

It requires less memory than a compiler because no object code


The compiler requires a lot of memory for generating object codes.
is generated.

Generates intermediate object code. No intermediate object code is generated.

For Security purpose compiler is more useful. The interpreter is a little vulnerable in case of security.

Examples: C, C++, C# Examples: Python, Perl, JavaScript, Ruby.

6. What is typecasting in datatype? Discuss the different types of typecasting in c language?

Typecasting in C is the process of converting one data type to another data type by the
programmer using the casting operator. There are two types of typecasting in c language:
• Implicit Casting: It performs the conversions without altering any of the values which are
stored in the data variable.
• Explicit Casting: In explicit type casting, we have to force the conversion between data types.

7. What is Error in programming? Discuss the


I. Syntax error
II. Logical error
III. Runtime Error
IV. System error

Errors in C programming are discrepancies that can cause a program to malfunction, leading to failures in
compiling, halting execution, or generating incorrect results.

Syntax Error- mistakes in typing the code's syntax correctly.

Logical Error- We do not get the output we expected after the compilation and execution of a program, Even
though the code seems error free

Runtime Error- When a program is running, and it is not able to perform any particular operation, it means that
we have encountered a run time error.

System Error - System errors are unexpected or abnormal events that occur during the execution of a program.

Module 2:-
1. What is operator? Discuss different types of operators in c language?

An operator in C can be defined as the symbol that helps us to perform some specific
mathematical, relational, bitwise, conditional, or logical computations on values and variables.

https://www.geeksforgeeks.org/operators-in-c/

2. What is precedence and associativity of operators?

The concept of operator precedence and associativity in C helps in determining which operators will be
given priority when there are multiple operators in the expression.

Operator
Precedence Description Associativity

() Parentheses (function call)

1 [] Array Subscript (Square Brackets) Left-to-Right

. Dot Operator
Operator
Precedence Description Associativity

-> Structure Pointer Operator

++ , — Postfix increment, decrement

++ / — Prefix increment, decrement

+/– Unary plus, minus

!,~ Logical NOT, Bitwise complement

2 (type) Cast Operator Right-to-Left

* Dereference Operator

& Addressof Operator

sizeof Determine size in bytes

3 *,/,% Multiplication, division, modulus Left-to-Right

4 +/- Addition, subtraction Left-to-Right

5 << , >> Bitwise shift left, Bitwise shift right Left-to-Right

< , <= Relational less than, less than or equal to

6 Left-to-Right

> , >= Relational greater than, greater than or equal to

7 == , != Relational is equal to, is not equal to Left-to-Right

8 & Bitwise AND Left-to-Right

9 ^ Bitwise exclusive OR Left-to-Right

10 | Bitwise inclusive OR Left-to-Right


Operator
Precedence Description Associativity

11 && Logical AND Left-to-Right

12 || Logical OR Left-to-Right

13 ?: Ternary conditional Right-to-Left

= Assignment

+= , -= Addition, subtraction assignment

*= , /= Multiplication, division assignment

14 Right-to-Left

%= , &= Modulus, bitwise AND assignment

^= , |= Bitwise exclusive, inclusive OR assignment

<<=, >>= Bitwise shift left, right assignment

15 , comma (expression separator) Left-to-Right

Module 3:-
1. What is control statements? Discuss the different types of Control statements?
Control statements in C are programming constructs that are used to control the flow of execution in a
program. These are of three types: Selection statements, Iteration statements, Switch statements.
Selection Statements Iteration statements Switch Statements
if (num > 0) { int i = 0; switch (num) {

printf("The number is positive\n"); while (i < 5) { case 0:

} else { printf("%d\n", i); printf("The number is zero\n");

printf("The number is negative\n"); i++; break;

} } case 10:

printf("The number is ten\n");

break;

default:

printf("The number is not zero or ten\n");

break;

2. What is looping? Discuss the different types of loops in c language? write it’s syntax.
Looping- Loops in programming are used to repeat a block of code until the specified condition is met.
Two types of loops : Entry controlled loops – For loop, While loop | Exit controlled loops- Do-while
loop.

Loop Type Description

first Initializes, then condition check, then executes the body and at last, the
for loop
update is done.

first Initializes, then condition checks, and then executes the body, and
while loop
updating can be inside the body.

do-while
do-while first executes the body and then the condition check is done.
loop

Syntax – For loop:

for (initialize expression; test expression; update expression)

// body of for loop

Syntax – While loop:

Initialization expression;

while (test expression)

// body of the while loop

update expression;

Syntax – do While loop:

Initialization expression;

do

// body of do-while loop

Update expression;

} while (test expression);

3. What is conditional control statements? Discuss the different types of conditional control
statements. Write the syntax of each.
The conditional statements (also known as decision control structures) such as if, if else, switch, etc. are used
for decision-making purposes in C programs.

https://www.geeksforgeeks.org/decision-making-c-cpp/
Module 4:-
1. What is datatype? Discuss the different types of datatypes in C language.

The data type is a collection of data with values having fixed values, meaning as well as its
characteristics. The data types in C can be classified as follows:

Types Description

Primitive data types are the most basic data


Primitive
types that are used for representing simple
Data Types
values such as integers, float, characters, etc.

User Defined The user-defined data types are defined by


Data Types the user himself.

The data types that are derived from the


Derived
primitive or built-in datatypes are referred to
Types
as Derived Data Types.

2. What is String? Discuss at least five pre-defined functions of string?


A String in C programming is a sequence of characters terminated with a null character ‘\0’. The C String is stored as an
array of characters. Pre-defined functions in string:

I. strcat() Function: Used for concatenation. Append a copy of source string to the end of destination string.
Syntax- [char* strcat(char* dest, const char* src);]
• The strcat() function returns a pointer to the dest string.
II. Strlen() Function: Calculates the length of a given string.
Syntax- [int strlen(const char *str);]
III. Strcmp() Function: This function takes two strings as arguments and compares these two strings lexicographically.
Syntax- [int strcmp(const char *str1, const char *str2);]
• If str1 is less than str2, the return value is less than 0.
• If str1 is greater than str2, the return value is greater than 0.
• If str1 is equal to str2, the return value is 0.
IV. Strcpy() Function: Use to copy one string in another.
Syntax- [char* strcpy(char* dest, const char* src);]
V. Strstr() Function: Used to search the first occurrence of a substring in another string.
Syntax- [char *strstr(const char *s1, const char *s2);]

• If the s2 is found in s1, this function returns a pointer to the first character of the s2 in s1, otherwise, it returns a
null pointer.
• It returns s1 if s2 points to an empty string.
https://www.geeksforgeeks.org/string-functions-in-c/?ref=lbp

Module 5:-
1. What is function? Discuss the different types of functions in C language.
A function in C is a set of statements that when called perform some specific task. It is the basic building block
of a C program that provides modularity and code reusability.
Two types of functions:
a)Library Functions - A library function is also referred to as a “built-in function”. A compiler package already exists that
contains these functions, each of which has a specific meaning and is included in the package. Example- pow(), strlen(),
sqrt(), printf(),scanf(),etc…
b)User-defined Functions- Functions that the programmer creates are known as User-Defined functions or “tailor-made
functions”. Whenever we write a function that is case-specific and is not defined in any header file, we need to declare and
define our own functions according to the syntax.
2. What is function prototype? Discuss the function prototype and function definition.
The C function prototype is a statement that tells the compiler about the function’s name, its return type,
numbers and data types of its parameters.

Syntax
return_type function_name(parameter_list);

Function Declaration Function Prototype


Function Definition- The function definition
consists of actual statements which are
The function prototype tells the executed when the function is called (i.e. when
Function Declaration is used to tell the
compiler about the existence
existence of a function. the program control comes to the function).
and signature of the function.

A function prototype is a
A function declaration is valid even function declaration that
with only function name and return provides the function’s name,
type. return type, and parameter list
without including the function
body.

Typically used in header files to Used to declare functions before


declare functions. their actual definitions.

Syntax:
Syntax:
return_type
return_type function_name();
function_name(parameter_list);

3. What is function parameter? Discuss the different types of methods to pass the parameter?

Argument Parameter

When a function is called, the values that are passed The values which are defined at the time of the function prototype or
during the call are called as arguments. definition of the function are called as parameters.

These are used in function call statement to send value These are used in function header of the called function to receive the value
from the calling function to the receiving function. from the arguments.

During the time of call each argument is always assigned Parameters are local variables which are assigned value of the arguments
to the parameter in the function definition. when the function is called.

They are also called Actual Parameters They are also called Formal Parameters

Example:
Example:
int Call(int rnum)
int num = 20; {
Call(num) printf("the num is %d", rnum);
}
// num is argument
// rnum is parameter

4. What is the difference between call by value and call by reference in functions in C?
Call By Value Call By Reference

While calling a function, we pass the address of


While calling a function, we pass the values of variables to it. Such
variables(location of variables) to the function known as “Call
functions are known as “Call By Values”.
By References.

In this method, the address of actual variables in the calling


In this method, the value of each variable in the calling function is
function is copied into the dummy variables of the called
copied into corresponding dummy variables of the called function.
function.

With this method, the changes made to the dummy variables in the With this method, using addresses we would have access to
called function have no effect on the values of actual variables in the the actual variables and hence we would be able to
calling function. manipulate them.

In call-by-values, we cannot alter the values of actual variables In call by reference, we can alter the values of variables
through function calls. through function calls.

Pointer variables are necessary to define to store the address


Values of variables are passed by the Simple technique.
values of variables.

// C program to illustrate Call by Reference


// C program to illustrate call by value
#include <stdio.h>
#include <stdio.h>

// Function Prototype
// Function Prototype
void swapx(int*, int*);
void swapx(int x, int y);

// Main function
// Main function
int main()
int main()
{
{
int a = 10, b = 20;
int a = 10, b = 20;

// Pass reference
// Pass by Values
swapx(&a, &b); // Actual Parameters
swapx(a, b); // Actual Parameters

printf("Inside the Caller:\na = %d b = %d\n", a, b);


printf("In the Caller:\na = %d b = %d\n", a, b);

return 0;
return 0;
}
}

// Function to swap two variables


// Swap functions that swaps
// by references
// two values
void swapx(int* x, int* y) // Formal Parameters
void swapx(int x, int y) // Formal Parameters
{
{
int t;
int t;

t = *x;
t = x;
*x = *y;
x = y;
*y = t;
y = t;

printf("Inside the Function:\nx = %d y = %d\n", *x,


printf("Inside Function:\nx = %d y = %d\n", x, y);
*y);
}
}

5. What is recursion? Discuss different types of recursions in C language?


Recursion is defined as a process which calls itself directly or indirectly and the corresponding function is
called a recursive function.

Types of Recursion:
1. Direct recursion: When a function is called within itself directly it is called direct recursion. This can be further
categorised into four types:
• Tail recursion,
• Head recursion,
• Tree recursion and
• Nested recursion.
2. Indirect recursion: Indirect recursion occurs when a function calls another function that eventually calls the
original function and it forms a cycle.

Module 6:-
1. What is pointer?
A pointer is defined as a derived data type that can store the address of other C variables or a memory
location. We can access and manipulate the data stored in that memory location using pointers.

Syntax - datatype * ptr;


https://www.geeksforgeeks.org/c-pointers/

2. Discuss the dynamic memory allocation methods? Write it’s syntax.

3. Write difference between malloc(), calloc() and realloc().

4. What is pointer to pointer? Give an example.


The pointer to a pointer in C is used when we want to store the address of another pointer. The first pointer is
used to store the address of the variable. And the second pointer is used to store the address of the first pointer.
That is why they are also known as double-pointers.
int val = 5;
int *ptr = &val; // storing address of val to pointer ptr.
int **d_ptr = &ptr; // pointer to a pointer declared
// which is pointing to an integer.
Example:
// C program to demonstrate pointer to pointer
#include <stdio.h>

int main()
{
int var = 789;

// pointer for var


int* ptr2;

// double pointer for ptr2


int** ptr1;

// storing address of var in ptr2


ptr2 = &var;

// Storing address of ptr2 in ptr1


ptr1 = &ptr2;

// Displaying value of var using


// both single and double pointers
printf("Value of var = %d\n", var);
printf("Value of var using single pointer = %d\n", *ptr2);
printf("Value of var using double pointer = %d\n", **ptr1);

return 0;
}

5. What is pointers arithmetic? How many arithmetic operators work on pointers?


Pointer Arithmetic is the set of valid arithmetic operations that can be performed on pointers .

These operations are:


1. Increment/Decrement of a Pointer
2. Addition of integer to a pointer
3. Subtraction of integer to a pointer
4. Subtracting two pointers of the same type
5. Comparison of pointers

Module 7:-
1. What is Structure? Write down the difference between structure and union.
The structure in C is a user-defined data type that can be used to group items of possibly different types into
a single type. The struct keyword is used to define the structure in the C programming language.

Difference between structure and union:

You might also like