Crack the interview c questions




















The variables inside a structure are called the members of the structure. Class: Class is a successor of the Structure. By default, all the members inside the class are private. Answer: Using Declaration is used to refer a name from the namespace without the scope resolution operator. This process is called name mangling. The inverse process is called as demangling.

Compile-time polymorphism is achieved by using an Overloading technique. Overloading simply means giving additional meaning to an entity by keeping its base meaning intact. Function Overloading: Function overloading is a technique that allows the programmer to have more than one function with the same name but different parameter list.

In other words, we overload the function with different arguments i. Function overloading is never achieved on its return type. In operator overloading, an operator is overloaded, so that it can operate on the user-defined types as well with the operands of the standard data type. But while doing this, the standard definition of that operator is kept intact. Answer: Method overloading is having functions with the same name but different argument lists.

This is a form of compile-time polymorphism. Method overriding comes into picture when we rewrite the method that is derived from a base class. Method overriding is used while dealing with run-time polymorphism or virtual functions. If we need to traverse through this collection of objects, we cannot do it using simple index variables.

Here, we are passing the address location number of a and b to the function1. This strategy manipulates the Actual Arguments. Enlist the Advantages of Macros over Variables. The advantages of using Macros over variables are as follows: A Compiler can generate faster and compact code for constants that for variables. There is always a risk that a variable may inadvertently get manipulated in the program. What is the difference between and? What is a continue keyword used for?

The Continue keyword allows us to transfer the program control back to the very first Line of the current Loop thereby bypassing the next statements after the Keyword. A Continue is usually associated with IF Block. How can you make scanf method accept Multi-Word Strings? Scanf function accepts a single string by default. Does Linux Ubuntu supports the Header file conio. Describe Modulus Operator?

Modulus Operator is used to fetch the Remainder value on dividing one Integer with another Integer. Modulus operator cannot work with Float values. Is an Else Block necessary for a Corresponding if Block? No, an If Block is generally independent of an Else Block. An Else Block is used only when a Conditional Approach is to be used.

Enlist Comparison Operator and Assignment Operator. An Assignment Operator is used to assign or set a value to a variable whereas a Comparison Operator is used to check a condition. Explain Conditional Operator. Conditional Operator is also called as Ternary Operator. The Syntax for a Conditional Operator is: expression 1? Depending upon its value, if the Condition evaluates to be True, expression 2 will be executed and if the Expression 1 evaluates to be False, expression 3 will be evaluated.

A While Loop checks the Condition before executing the following set of statements whereas a Do-While Loop first executes the set of statements once and then checks the condition. In this, statement will be executed at least once even if the Condition evaluates to be False.

What is a break keyword used for? The keyword break allows us to transfer the Control to the very first statement that occurs after the current Loop.

It therefore takes the Execution Control out of the Loop. A Switch Case Structure leads to a more structured program and the level of indentation is manageable, more so, if there are multiple statements with each case of a Switch.

Enlist Limitations of Switch Case Structure? A Float expression cannot be tested in a Switch Case. It is illegal to use same expressions for multiple cases. What is the significance of a Null Character in String? It is different than 0. Null Character is a terminating Character for an Array of Characters i. It is the only way to track the end of a String. What is the difference between function and function ;? What is the role of a return statement? On executing the return statement, it immediately transfers the control back to the Calling function.

It returns the value present in the parentheses after return statement to the calling function. Explain Automatic Storage Class. Syntax: auto int a; Storage: Memory Life: Till the control remains within the block in which the variable is defined. If the callee function changes the value addressed at the passed address it will be visible to the caller function as well.

When we assign a variable it takes space of our RAM either heap or RAM dependent on the size of data type, however, if a programmer uses a memory available on the heap and forgets to a delta it, at some point all the memory available on the ram will be occupied with no memory left this can lead to a memory leak.

To avoid memory leaks, you can trace all your memory allocations and think forward, where you want to destroy in a good sense that memory and place delete there. C is a language known for its low-level control over the memory allocation of variables in DMA there are two major standard library malloc and free.

The malloc function takes a single input parameter which tells the size of the memory requested It returns a pointer to the allocated memory. If the allocation fails, it returns NULL. The prototype for the standard library function is like this:. No indication of success or failure is returned. The function prototype is like this:. They are:. In most cases, we use typedef's to simplify the existing type declaration syntax.

Or to provide specific descriptive names to a type. With typedef, you can simply create an alias for any type. Whether it is a simple integer to complex function pointer or structure declaration, typedef will shorten your code. The standard input library gets reads user input till it encounters a new line character. Bonus: It remained an official part of the language up to the ISO C standard, but it was officially removed by the standard.

Most C implementations still support it, but at least GCC issues a warning for any code that uses it. In practice, the difference is in the location where the preprocessor searches for the included file. This method is normally used to include programmer-defined header files. The dangling pointer points to a memory that has already been freed.

The storage is no longer allocated. Trying to access it might cause a Segmentation fault. A common way to end up with a dangling pointer:. You are returning an address that was a local variable, which would have gone out of scope by the time control was returned to the calling function.

Undefined behavior. In the figure shown above writing to a memory that has been freed is an example of the dangling pointer, which makes the program crash. A memory leak is something where the memory allocated is not freed which causes the program to use an undefined amount of memory from the ram making it unavailable for every other running program or daemon which causes the programs to crash.

There are various tools like O profile testing which is useful to detect memory leaks on your programs. In C double-quotes variables are identified as a string whereas single-quoted variables are identified as the character. Another major difference being the string double-quoted variables end with a null terminator that makes it a 2 character array. Circular linked list is a variation of a linked list where the last node is pointing to the first node's information part.

Therefore the last node does not point to null. It is majorly related to how the compiler reads or parses the entire code and breaks it into a set of instructions or statements , to which semicolon in C acts as a boundary between two sets of instructions.

The difference between the Source Code and Object Code is that Source Code is a collection of computer instructions written using a human-readable programming language while Object Code is a sequence of statements in machine language, and is the output after the compiler or an assembler converts the Source Code.

The last point about Object Code is the way the changes are reflected. When the Source Code is modified, each time the Source Code needs to be compiled to reflect the changes in the Object Code. In C header files must have the extension as. The header is useful to import the above definitions to the source code using the include directive.

For example, if your source code needs to take input from the user do some manipulation and print the output on the terminal, it should have stdio. The most obvious use of this is a function that returns nothing:.

The other use for the void keyword is a void pointer. A void pointer points to the memory location where the data type is undefined at the time of variable definition.

A dynamic data structure DDS refers to an organization or collection of data in memory that has the flexibility to grow or shrink in size, enabling a programmer to control exactly how much memory is utilized.

Dynamic data structures change in size by having unused memory allocated or de-allocated from the heap as needed. In these tricky C programs, we will write a C program to add two numbers without using the addition operator. The bitwise complement operator is used in this program. The left shift operator shifts all bits towards the left by a certain number of specified bits. While you travel the linked list, change the current node's next pointer to point to its previous element.

You also need another pointer to store the next node before changing the reference. Also when we are done return the new head of the reversed list. Below is the source code for C Program to Check for Balanced Parentheses using Stack which is successfully compiled and run on Windows System to produce desired output as shown below :. Fibonacci sequence is characterized by the fact that every number after the first two is the sum of the two preceding ones.

For example, consider below sequence. Merge two sorted linked lists and return them as a sorted list. The list should be made by splicing together the nodes of the first two lists.

Memory Complexity Constant, O 1. Maintain a head and a tail pointer on the merged linked list. Then choose the head of the merged linked list by comparing the first node of both linked lists. For all subsequent nodes in both lists, you choose the smaller current node and link it to the tail of the merged list, and moving the current pointer of that list one step forward.

You keep doing this while there are some remaining elements in both lists. If there are still some elements in only one of the lists, you link this remaining list to the tail of the merged list.

Initially, the merged linked list is NULL. Compare the value of the first two nodes and make the node with the smaller value the head node of the merged linked list. In this example, it is 4 from head1. Then move head1 one step forward.



0コメント

  • 1000 / 1000