In file1.cwe have static int i = 5;and int *ptr = &i;now value of ptr is written in some file say abc.txtnow file2.c (another program) opens abc.txtread the valueand print the value loacted at dat adress saywhat will be the o/p????example i = 5;ptr = &i; ptr has now 0xABFF0xABFF is written in abc.txtfile2.c opens the abc.txt and read the value 0xABFFnow print the value present at this addresswaht it will print????ANSWER:A program has nothing...
Sunday, March 28, 2010
The solution is to iterate down the list looking for the correct place to insert the new node. That could be the end of the list, or a point just before a node which is larger than the new node.Note that we assume the memory for the new node has already been allocated and a pointer to that memory is being passed to this function.// Special case code for the head endvoid linkedListInsertSorted(struct node** headReference, struct node* newNode){...
When a program is loaded into memory, it is organized into three areas of memory, called segments: the text segment, stack segment, and the heap segment. The text segment (sometimes also called the code segment) is where the compiled code of the program itself resides. This is the machine language representation of the program steps to be carried out, including all functions making up the program, both user defined and system.The remaining...
Most compilers recognized the file type by looking at the file extension.You might also be able to force the compiler to ignore the file type by supplying compiler switch. In MS VC++ 6, for example, the MSCRT defines a macro, __cplusplus. If you undefine that macro, then the compiler will treat your code as C code. You don't define the __cplusplus macro. It is defined by the compiler when compiling a C++ source. In MSVC6 there's a switch for the...
Linkage is used to determine what makes the same name declared in different scopes refer to the same thing. An object only ever has one name, but in many cases we would like to be able to refer to the same object from different scopes. A typical example is the wish to be able to call printf() from several different places in a program, even if those places are not all in the same source file.The Standard warns that declarations which refer to the...
This questions is asked almost always in every interview.The best way to swap two variables is to use a temporary variable.int a,b,t;t = a;a = b;b = t;There is no way better than this as you will find out soon. There are a few slick expressions that do swap variables without using temporary storage. But they come with their own set of problems.Method1 (The XOR trick)a ^= b ^= a ^= b;Although the code above works fine for most of the cases, it tries...
A sorting program that sorts items that are on secondary storage (disk or tape) rather than primary storage (memory) is called an external sort. Exactly how to sort large data depends on what is meant by ?too large to fit in memory.? If the items to be sorted are themselves too large to fit in memory (such as images), but there aren?t many items, you can keep in memory only the sort key and a value indicating the data?s location on disk. After the...
Both Merge-sort and Quick-sort have same time complexity i.e. O(nlogn). In merge sort the file a[1:n] was divided at its midpoint into sub-arrays which are independently sorted and later merged. Whereas, in quick sort the division into two sub-arrays is made so that the sorted sub-arrays do not need to be merged latter....
A Heap is an almost complete binary tree.In this tree, if the maximum level is i, then, upto the (i-1)th level should be complete. At level i, the number of nodes can be less than or equal to 2^i. If the number of nodes is less than 2^i, then the nodes in that level should be completely filled, only from left to right.The property of an ascending heap is that, the root is the lowest and given any other node i, that node should be less than...
Great C datastructure question!The answer is ofcourse, you can write a C program to do this. But, the question is, do you really think it will be as efficient as a C program which does a binary search on an array?Think hard, real hard.Do you know what exactly makes the binary search on an array so fast and efficient? Its the ability to access any element in the array in constant time. This is what makes it so fast. You can get to the middle...
One way is to reverse the data in the nodes without changing the pointers themselves. One can also create a new linked list which is the reverse of the original linked list. A simple C program can do that for you. Please note that you would still use the "next" pointer fields to traverse through the linked list (So in effect, you are using the pointers, but you are not changing them when reversing the linked list)....
A SQL JOIN clause combines records from two or more tables in a database. It creates a set that can be saved as a table or used as is. A JOIN is a means for combining fields from two tables by using values common to each. ANSI standard SQL specifies four types of JOINs: INNER, OUTER, LEFT, and RIGHT. In special cases, a table (base table, view,...
Wednesday, March 17, 2010
A majority element in an array A, of size N is an element that appears more than N/2 times (and hence there is atmostone such element)Write a function which takes an array and emits the majority element (if it exists), otherwise prints NONE as follows:I/P : 3 3 4 2 4 4 2 4 4O/P : 4I/P : 3 3 4 2 4 4 2 4O/P : NONEObvious answer is create a binary search tree. When you get one element insert it. If the element exists increase count by one in the node....
Subscribe to:
Posts (Atom)