Youtube Channel

C

What do you mean by a sequential access file?

- While writing programs that store and retrieve data in a file, it is possible to designate that file into different forms.
- A sequential access file is such that data are saved in sequential order: one data is placed into the file after another.
- If you want to access a particular data within the sequential access file, data has to be read - one data at a time, until you reach the data you want.

Explain zero based addressing.

- The array subscripts always start at zero.
- These subscript values are used to identify the elements in the array.
- Since subscripts start at 0,arrays are said to use zero-based addressing.

Are bit fields portable?

- No, Bit fields are not portable.
- Since Bit fields cannot span machine words and the number of bits in a machine word is different on different machines, a particular program using bit fields might not compile on some machines.
- One should avoid using bit fields except when the machines can directly address bits in memory and the compiler can generate code.

Explain high-order and low-order bytes.

- The numbers are written from left to right in the decreasing order of significance. Similarly, the bits in a byte of computer memory can be considered as digits of a number written in base
- The byte holding the least significant 8 bits is called the low-order byte.
- The byte holding the most significant 8 bits is the most significant byte, or high- order byte.

What are the different types of endless loops?

An endless loop can be of two types
i.) A loop that is intentionally designed to go round and round until the condition within the loop is met. Once the condition is met, a break function gets the program out of the loop.
ii.) A loop condition written by mistake, causing the loop to run erroneously forever. Endless loops are also referred to as infinite loops.


Why are all header files not declared in every C program?

- Declaring all header files in every program would lead to increase in the overall file size and load of the program. It is not a good programming.
- The choice header files that you want to declare in the program depends on the commands/functions you want to use in the program. Each header file contains different commands and functions. So we use only the files relevant to our program.

Which one would you prefer - a macro or a function?

It actually depends on the purpose of the program!
- In case of macros, the corresponding code is inserted directly into your source code at the point where macro is called. There is no overhead involved in using a macro.This makes the Macros more efficient and faster than functions. However, macros are usually small and cannot handle large, complex coding constructs. So, if it is a complex situation that the program wants to handle, functions are more suitable.
- Macros are expanded inline - this means that every time a macro occurs, the code is replicated. So, the code size in case of usage of macros will be larger in comparison to functions.
So, the choice of using macros or functions actually depends of your requirement - speed vs program size.
If your program contains small, repeated code sections, you should use Macros. If the program requires, large number of unique code lines - you should prefer functions.


What is break statement?

- A break statement causes the loop to terminate. The control then passes to the statement following the body of the loop.

Explain spaghetti programming.

- Spaghetti programming refers to codes that tend to get tangled and overlapped throughout the program.
- It makes a program complex and analyzing the code becomes difficult. It usually happends due to the lack of work experience on developer's part.

Differentiate between the = symbol and == symbol?

- The = symbol is usually used in mathematical operations. It is used to assign a value to a given variable while the == symbol is a relational operator that is used to compare two values.

What are actual arguments?

- When some functions are created and used to perform an action on some given values, some values need to be passed to them. The values that are passed into the called function are referred to as actual arguments.

What is a newline escape sequence?

- A newline escape sequence is represented by the \n character.
- It is used to insert a new line while displaying the output data.
- To add more spaces you can use more \n characters.

How many levels deep can include files be nested?

- As such, there is no limit to the number of levels of nested include files you can have but your compiler might run out of stack space while trying to include an inordinately high number of files. This number depends on your hardware configuration and compiler.
- Although it is legal to nest include files yet you must avoid it. An include level should be created only where it is required and makes sense, like creating an include file that has an #include statement for each header required by the module you are working with.


What are pre-processor directives?

- Pre-processor directives are placed at the beginning of a C program. They begin with # symbol.
- This is the place, where library files are specified depending on the functions to be used in the program.
- Pre-processor directives are also used for declaration of constants.

What are compound statements?

- Compound statements are made up of two or more program statements which are executed together. They can be executed with a loop.
- Curly brackets { } are placed before and after compound statements.
- Compound statements are usually used while handling conditions in which a series of statements are executed when a TRUE or FALSE is evaluated.

How does placing some code lines between the comment symbol help in debugging the code?

- Placing comment symbols /* */ around a code isolates some code that the coder believes might be causing the errors in the program, without deleting it. - If the code is correct, you can just remove the comment symbols, without needing to retype it.
- If it is wrong, you can just remove it.

Is it possible to pass an entire structure to functions?

Yes, it is possible to pass an entire structure to a function in a call by method style. Some programmers prefer to declare the structure globally, then pass a variable of that structure type to a function. It helps in maintaining the consistency and uniformity in terms of argument type.

What are header files? What are their uses?

- Header files are also called as library files.
- They carry two important things: the definitions and prototypes of functions being used in a program.
- For example: stdio.h is a header file that contains definition and prototypes of commands like printf and scanf.

Is it possible to create your own header files?

- Yes, it is possible to create a customized header file.
- To do this, you just need to include the function prototypes that you want to use in your program in it, and use the #include directive followed by the name of your header file.

Why is a semicolon (;) put at the end of every program statement?

- It is done for parsing process and compilation of the code.
- A semicolon acts as a delimiter. This tells the compiler where each statement ends, and can proceed to divide the statement into smaller elements for checking the syntax.

How do you access the values within an array?

- Arrays contain a number of elements, depending on the size you assigned it during variable declaration.
- Each element is assigned a number from 0 to number of elements-1.
- To assign or retrieve the value of a particular element, refer to the element number. For example: if you have a declaration that says “intmarks[6];”, then you have 6 accessible elements, namely: marks[0], marks[1], marks[2], marks[3], marks[4] and marks[5].

What is the role of && operator in a program code?

- The && is also referred to as AND operator.
- When this operator is used, all conditions specified must be TRUE before the next action can be carried out.
- If any of the conditions is false, the whole statement is false.

Differentiate between functions getch() and getche().

- Both functions accept a character input value from the user.
- When getch() is used, the key that was pressed will not appear on the screen. It is automatically captured and assigned to a variable.
- While when getche() is used, the key that was pressed by the user appears on the screen and is assigned to a variable.

What are the various types of control structures in programming?

- Mainly there are 3 types of control structures in programming: Sequence, Selection and Repetition.
- Sequential control follows a top- down flow in executing a program. This means that step 1 is first executed, followed by step 2 and so on.
- Selection means dealing with conditional statements. This means that the code is executed depending on the evaluation of conditions a TRUE or FALSE. It means that not all codes may be executed and there are alternative flows within.
- Repetitions are also called as loop structures. They will repeat one or two program statements as set by a counter.

Differentiate between the expression “++a” and “a++”?

- With ++a, the increment happens first on variable a, and the resulting value is used. This is called as prefix increment.
- With a++, the current value of the variable will be used in an operation. This is called as postfix increment.

What are control structures?

- Control structures decide which instructions in the program should be executed.
- This implies that the program flow may not necessarily move from one statement to the next one. Some alternative portions may be executed depending on the conditional statements.

Explain enumerated types.

- Enumerated types allow the programmers to use more meaningful words as values to a variable.
- Each item in the enumerated type variable is actually associated with a numeric code. For an enumerated type variable named Months can be created. Its values can be January, February,....December.

Are comments included during the compilation stage and placed in the EXE file as well?

- No, comments encountered by the compiler are disregarded.
- Their only purpose is guidance and ease of programmer. They have no effect on the functionality of the program.


Tell us something about keyword "auto".

- "Automatic" is a local variable with a local lifetime.
- It is declared by auto storage-class specifier.
- This variable is visible only in the block in which it is declared.
- The value of uninitialized auto variables is undefined.
- The variables with auto storage class need to be initialised while storing them or initial values need to be assigned to them in statements within the block.

Explain the meaning of keyword 'extern' in a function declaration.

- 'extern' modifier in a method declaration implies that the method is implemented externally.
- The program doesn't reserve any memory for a variable declared as 'extern'.
- A variable that is required to be used in every file of the project is declared globally in one file - and not inside any function.
- 'extern' declaration of that variable is added to a header file not included in all others.

Differentiate between #include<...> and #include "..."

- #include<...> means that the directories other than the current one will be searched for the header file.
- #include "..." means that the current directory will be searched for the header file before any other directories.

Situation - The 'sizeof' operator reported a larger size than the calculated size for a structure type. What could be the reason?

- The 'sizeof' operator shows the amount of storage needed to store an object of the specified type of operand.
- The result of applying it to a structure type name is the number of bytes including internal and trailing padding.
- This may inlcude internal leading & trailing padding used for the alignment of structure on memory boubdaries. This may cause the error.

What does *p++ do? What does it point to?

- *p++ increments p.
- It returns the value pointed to by p before incrementation.

Explain "Bus Error".

- It is a fatal error in the execution of a machine language instruction.
- It occurs because the procesor detects an abnormal condition on its bus.
- The causes may be:
- Invalid address alignment.
- Accessing a physical address that does not correspond to any device.
- Other device specific hardware error.

What are volatile variables?

Volatile variables are like other variables except that the values might be changed at any given point of time only by ‘some external resources’.
Ex:
volatile int number;
The value may be altered by some external factor, though if it does not appear to the left of the assignment statement. The compiler will keep track of these volatile variables. 





What do you think about the following?

int i;
scanf("%d", i);
printf("%d", i);

- The program will compile without any errors.
- When you try to enter a value using "stdin", the system will try to store the value at location with address "i". "i" might be invalid leading the program to crash and core dump.
- It implies that this code has a bug.

What will be the output of the following?

int main()

main();
return 0;

- Runt time error. Stack overflow.

What are the advantages os using linked list for tree construction?

- Unless the memory is full, overflow will never occur.
- Insertions & deletions are easier in comparison to arrays.
- Moving pointer is faster & easier in comparison to moving items when records are large.

Which data structure is used to perform recursion?

- Stack data structure is used to perform recursion.
- Its LIFO property stores return addresses of the 'caller' and its successions in recursion to find where the execution control should return.

Explain the following.

a.) Queue -
- Queue is a FIFO or LIFO data structure.
- It permits two operations - enqueue & dequeue.
- The methods used to check the status of the queue are - empty() and full()

b.) Priority Queues -
- List of items with priority associated with it.
- Priority queues effectively support finding the item with highest priority across a series of operations.
- Basic priority queue operations are - insert, find maximum or minimum, delete maximum or minimum.

Explain the following.

a. ) Binary height balanced tree-
- It is a binary tree in which for every node the heights of left and right subtree differ by not more than 1.

b.) Ternary tree -
- In this tree a node can have zero or more child nodes.

c.) Red-black trees -
It is a binary search tree with following propoerties:
- Root is black.
- Every leaf is black.
- Every node is either red or black.
- For a red red node, both its children are black.
- All internal nodes have two children .
- Every simple path from node to a descendant leaf contains the same no. of black nodes.

What is "Bus error"?

A ‘bus error’ is certain undefined behavior result type. The cause for such error on a system could not be specified by the C language. The memory accessibility which CPU could not address physically, ‘bus error’ occurs. Also, any fault detected by a device by the computer system can also be a ‘bus error’. These errors caused by programs that generate undefined behavior which C language no longer specifies what can happen.

Throw some light on the following.

a.) Splay trees -
- These are self adjusting binary search trees.
- They can adjust optimally to any sequence of tree operations.
- Evertime a node of the tree is accessed, a radical surgery is performed on it. This results into the newly accessed node turning into the root of the modified tree.
- Splaying steps used are: Zig rotation, Zag rotation, Zig-zag, Zag-zig, Zig-zig, Zag-zag.

b.) B tree -
- The root is either a tree leaf or has atleast two children.
- Each node (except root & tree leaves) has between ceil(m/2) and m children. Ceil being the ceiling function.
- Each path from root to tree leaf has same length.

Explain -

a.) Threaded binary trees -
- Every node without a right child has a link(thread) to its INORDER successor.
- This threading avoids the recursive method of traversing a tree which makes stacks & consumes a lot of memory & time.

b.) B+ tree -
- Consists of root, internal nodes and leaves.
- Root may be a leaf or internal node with two or more children.
- For a B+ tree of order v, internal nodes contain between v and 2v keys. A node with 'k' keys has 'k+1' children.
- Leaves exist on same level. They are the only nodes with data pointers.

Differentiate between full, complete & perfect binary trees.

- Full binary tree - Each node is either a leaf or internal node with exactly two non-empty children.
- Complete binary tree - For a tree with height 'a', every level is completely filled, except possibly the deepest one. At depth 'a', all nodes must be as far left as possible.
- Perfect binary tree - For a tree with height 'd', every internal node has two children and all the leaf nodes exist at same level.

Explain the use of keyword 'register' with respect to variables.

- It specifies that variable is to be stored in a CPU register.
- 'register' keyword for variables and parameters reduces code size.
- The no. of CPU registers is dependent on its architectural design. Mostly this number is 32.

Define recursion in C.

A programming technique in which a function may call itself. Recursive programming is especially well-suited to parsing nested markup structures  

What is the purpose of "register" keyword?

The keyword ‘register’ instructs the compiler to persist the variable that is being declared , in a CPU register.
Ex: register int number;
The persistence of register variables in CPU register is to optimize the access. Even the optimization is turned off; the register variables are forced to store in CPU register.