CP Cheatsheet
CP Cheatsheet
CP Cheatsheet
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 - 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 - 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 - 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 - 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 - Size of(9.2)
A - 8 bytes (9.2 is treated as a double)
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 - 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- Precedence of operators in C-
IEEE 754 representations-
1. Single precision (float)- 32 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.