You are on page 1of 11

CP Questions

Q - What is OS?
A - An operating system acts as an intermediary between the user of a
computer and computer hardware. The purpose of an operating system is to
provide an environment in which a user can execute programs conveniently
and efficiently.

Q - How we represent negative numbers


A - We can represent negative numbers by 2’s complement method.

Q - Why don't we use 1's complement


A - 1’s complement have 2 different representations for 0, -0 and +0 are
different when it comes to 1’s complement so 2’s complement is preferred
over 1’s complement to avoid confusion

Q - What is out of bounds error


A - When we try to access an index in the array which is beyond the size of
the array.

Q - Difference between array of pointer and pointer to an array


A - Array of pointers is an array of memory locations containing multiple
pointers to different (or same) memory locations. Meanwhile a pointer to an
array is a single pointer that points towards the starting of the array.

Q - floating point represent in compiler


A - using IEEE 754 format.

Q - How we represent floating point No.


A - Floating point numbers are represented as 1.Single precision format,
2.double precision format, according to IEEE 754.

Q - Linker working
A - Linker is a program in a system which helps to link an object module of
program into a single object file.

Q - Life cycle of c program


A -
Q - Diff methods to define neg no.
A - 1’s complement and 2’s complement

Q - Kaise hum memory free karenge


A - free() function can free all the memory allocated to a pointer.

Q - What are the advantages of a function


A -
1. Saves time since you don't have to write the same code again and
again.
2. fYou can pass variables as parameters so that you can perform
repetitive operations easily by just calling the function and passing
the required parameter.
3. It makes the code simpler and easy to read, which also makes it easy
to debug.

Q - What is a dangling pointer


A - Dangling pointer occurs at the time of the object destruction when the
object is deleted or de-allocated from memory without modifying the value
of the pointer. In this case, the pointer is pointing to the memory, which
is de-allocated.

Q - Difference between Malloc and calloc.


A -
1. Malloc() function will create a single block of memory of size
specified by the user. Calloc() function can assign multiple blocks
of memory for a variable.
2. Malloc function contains garbage values. The memory block allocated
by a calloc function is always initialized to zero.

Q - Dynamic allocation
A - Allocating memory at runtime is dynamic allocation. It can be done
using functions in stdlib.h.
Q - Which sorting algorithm will you use selection sort or bubble sort

A -

Q - Stack overflow
A - When a program attempts to use more space than is available on the call
stack, the stack is said to overflow.

Q - Strlen ka use
A - returns the length of the string that is passed into it as a parameter.
Note that it doesn't count the ending ‘\n’ (That marks the end of
the string) as part of the string.
Eg - strlen(“Hello World”) returns the value 11.

Q - Void pointer
A - A void pointer is a pointer that has no associated data type with it. A
void pointer can hold an address of any type and can be type casted to any
type.

Q - Memory segment
A - The memory layout contains different segments, like text segment which
contains machine code and heap segment which is used to allocate memory at
run time. So these segments are called memory segment

Q - negative number represent


A - We can represent negative numbers in several ways. The simplest is to
simply use the leftmost digit of the number as a special value to represent
the sign of the number: 0 = positive, 1 = negative. For example, a value of
positive 12 (decimal) would be written as 01100 in binary, but negative 12
(decimal) would be written as 11100.

Q - One numerical based on increment operator


A -

Q - User and kernel mode


A - When the program is running without requiring any input output devices,
then it is in user mode. But as soon as it requires any input or output
device, cpu generates a system call and the program is in kernel mode now.

Q - Dangling pointer
A - A pointer which was earlier pointing to some memory, but the memory is
now deallocated, then the pointer is a dangling pointer.

Q - Storage classes in c
A - Storage class is an attribute that changes the behavior of a variable.
It controls the lifetime, scope, storage location and initial value. The
storage classes are

Q - Type casting in c
A - Type casting means changing one date type to another. It can be
implicit as well as explicit.
Explicit - done by us. Implicit- done by compiler.

Q - Difference between structure and union


A
Properties Structure Union

Keywords struct is used to declare union is used to declare a


a structure. union

Size Size of the structure is Size of the union is equal to


equal to the sum of the the size of the greatest
sizes of its members. member in the union.

Memory Each member within a Memory allocated is shared by


structure is assigned a union members.
different memory area.

Value Altering the value of a Altering the value of one


member will not affect the member will alter the value
value of other members. of other members too.

Accessing Individual members can be Only one member can be


members accessed at a time. accessed at a time.
-

Q - Can we add and subtract two pointers


A - Yes, we can subtract two pointers. But we cannot add two pointers.

Q - explain booting process


A - steps-
1. The power supply is turned on and the computer hardware comes into
play.
2. Motherboard consists of SMPS(switch mode power supply) which will
regulate power supply to the motherboard.
3. Then POST(power on self test) is used to check whether all the
hardwares are working properly or not.
4. After successful execution of POST bootstrapping is enabled in which
system files are searched for in HDD, then in CD ROM and then in Pen
Drive if inserted.
5. After the files are found, they will load in RAM and system starts.

Q - boundary check condition in array


A - Check for each index, index>=0 and index < size of the array.

Q - static function
A - Unlike global functions in C, access to static functions is restricted
to the file where they are declared. Therefore, when we want to restrict
access to functions, we make them static.

Q - modifiers in c
A - Modifiers are keywords in c which changes the meaning of basic data
type in c. Data type modifiers- short, long, long long, signed, unsigned.

Q - Memory leak.
A - The memory leak occurs, when a piece of memory which was previously
allocated by the programmer. Then it is not deallocated properly by the
programmer. That memory is no longer in use by the program. So that place
is reserved for no reason. That's why this is called the memory leak.

Q - Define structure pointer


A - A pointer to a structure holds the address of the entire structure and
the structure members can be accessed using the arrow (->) operator.

Q - Size of(9.2)
A - 8 bytes (9.2 is treated as a double)

Q - Static storage class


A - The static storage class instructs the compiler to keep a local
variable in existence during the life-time of the program instead of
creating and destroying it each time it comes into and goes out of scope.

Q - Time complexity
A - Time complexity tells us the relative amount of time a particular
algorithm takes to run. Time Complexity of algorithm/code is not equal to
the actual time required to execute a particular code but the number of
times a statement executes.
It is represented by O() <Said as Big O>

Q - Space complexity
A - Space complexity is the amount of memory used by the algorithm
(including the input values of the algorithm), to execute it completely and
produce the result.

Q - what is time complexity in binary search


A - O(𝑙𝑜𝑔2𝑁)

Q - Bubble sort and its TC.


A - Bubble Sort is the simplest sorting algorithm that works by repeatedly
swapping the adjacent elements if they are in wrong order.
2
T.C. -> O(𝑛 )

Q - Selection sort and its TC.


A - The selection sort algorithm sorts an array by repeatedly finding the
minimum element from the unsorted part and putting it at the beginning. The
algorithm maintains two subarrays in a given array.
1) The subarray which is already sorted.
2) Remaining subarray which is unsorted.
2
T.C. -> O(𝑛 )

Q - Sizeof(9.9)
A - 8 bytes (treated as double)
Q - Size of 4.0
A - 8 bytes (treated as double)

Q - Multitasking vs Multiprogramming?
A - Multiprogramming:-
In case of multiprogramming,a number of processes are being loaded in RAM,
and it is non-preemptive in nature, i.e. If any process is
incomplete/Involves I/O operation then it will again go to the ready queue.
While in case of multitasking, a definite amount of time is allotted to a
task,and it is preemptive in nature, i.e ,it will execute the next task
after allotted time even if the process is incomplete.

Q- What are the different flows of a program?


A- Sequential, Conditional and Repetitive.

Q - Size of any pointer?


A - Usually it depends upon the word size of the underlying processor… for
example for a 32 bit computer the pointer size can be 4 bytes for a 64 bit
computer the pointer size can be 8 bytes.

Q- Precedence of operators in C-
IEEE 754 representations-
1. Single precision (float)- 32 bits

Sign- 1 bit Exponent- 8 bits Mantissa- 23 bits

2. Double precision (double) - 64 bits

Sign- 1 bit Exponent- 11 bits Mantissa- 52 bits

E.g.- representing 12.125


Step 1) convert to binary
=1100.001
Step 2) normalize the number i.e. keep only one digit to the left of
the decimal
=1.100001*2^3, so mantissa is 100001.
Step 3)in case of single precision, equate power of 2 to E-127, and
in case of double precision, equate power of 2 to E-1023, and obtain the
value of E.
Step 4)we have got sign ( 0 for positive), exponent E, and mantissa(
the number after decimal), so represent it as

Single precision 0 10000010 10000100000…

Double precision 0 10000000010 10000100000…

BCD (binary coded decimal)


Represent each digit in 4 bits binary and concatenate. Used in calculators,
LEDs, etc.
E.g. 255= (0010 0101 0101)

Decimal dotted notation


Used in IP addresses..
Represent each dot separated number in 8 bits binary.
Thus in IP addresses each number is from 0-255.
Ipv4 uses 32 bits representation as above. In the case of ipv6 it is 128
bits.

Types of pointers in C-
Null Pointer
We can create a null pointer by assigning null value during the pointer
declaration. This method is useful when you do not have any address
assigned to the pointer. A null pointer always contains value 0.

Void Pointer
In C programming, a void pointer is also called a generic pointer. It does
not have any standard data type. A void pointer is created by using the
keyword void. It can be used to store an address of any variable.

Wild pointer
A pointer is said to be a wild pointer if it is not being initialized to
anything. These types of C pointers are not efficient because they may
point to some unknown memory location which may cause problems in our
program and it may lead to crashing of the program.

Dangling pointer-
A pointer which was earlier pointing to some memory, but the memory is now
deallocated, then the pointer is a dangling pointer. It can be resolved by
assigning its value as NULL.
Complex pointer
Near pointer
Far pointer
Huge pointer

Q-Storage classes in c
A-Auto, extern, register, static are the four different storage classes in a C program
Q-Recursion in C
A-Recursion is the process of repeating items in a self-similar way. In
programming languages, if a program allows you to call a function inside the same
function, then it is called a recursive call of the function. The C programming
language supports recursion, i.e., a function to call itself.
Q-Stactic storage class
A-static: This storage class is used to declare static variables which are
popularly used while writing programs in C language. Static variables have a
property of preserving their value even after they are out of their scope! Hence, static
variables preserve the value of their last use in their scope.

You might also like