-
Insert New Value to Sorted Array
Write a pseudo code to insert new value x to an already sorted array of 1,000,000,000 numbers at its appropriate position in an optimum way?
-
All Possible Combinations Using Coins
Write a pseudo code in which using coins of Rs 1 Rs., 2 Rs., 5 Rs. and 10 Rs, find all possible combination of to pay  X amount. X can be any amount. For Example, There are 3 ways to give change for Rs. 4  using coins mentioned above:
1+1+1+1
1+1+2
2+2
-
Bit fields memory aligment with unsigned int, short int.
I have a structure.
struct {
int a : 8;
int b : 10;
int c : 12;
int d : 4;
int e : 3;
int : 0;
int f : 1;
char g;
} A;
The size of bitfields memory is 48bits.
The size of structure should be 4+4+1 bytes = 9 bytes. What about the memory for variable g. why memory for g is not allocated separately.... -
What is the difference between goto and longjmp() and setjmp()?
A goto statement implements a local jump of program execution, and the longjmp() and setjmp() functions implement a nonlocal, or far, jump of program execution. Generally, a jump in execution of any kind should be avoided because it is not considered good programming practice to use such statements as goto and longjmp in your program. A goto statement simply bypasses code in your program and jumps...
-
Is it acceptable to declare/define a variable in a C header?
A global variable that must be accessed from more than one file can and should be declared in a header file. In addition, such a variable must be defined in one source file. Variables should not be defined in header files, because the header file can be included in multiple source files, which would cause multiple definitions of the variable. The ANSI C standard will allow multiple external definitions,...
-
What is the easiest searching method to use?
Just as qsort() was the easiest sorting method, because it is part of the standard library, bsearch() is the easiest searching method to use. If the given array is in the sorted order bsearch() is the best method. Following is the prototype for bsearch(): void *bsearch(const void *key, const void *buf, size_t num, size_t size, int (*comp)(const void *, const void*)); Another simple searching...
-
How can I sort a linked list?
Both the merge sort and the radix sort are good sorting algorithms to use for linked lists.
-
How can I search for data in a linked list?
Unfortunately, the only way to search a linked list is with a linear search, because the only way a linked list’s members can be accessed is sequentially. Sometimes it is quicker to take the data from a linked list and store it in a different data structure so that searches can be more efficient.
-
What is Preprocessor?
The preprocessor is used to modify your program according to the preprocessor directives in your source code. Preprocessor directives (such as #define) give the preprocessor specific instructions on how to modify your source code. The preprocessor reads in all of your include files and the source code you are compiling and creates a preprocessed version of your source code. This preprocessed version...
-
How many levels deep can include files be nested?
Even though there is no limit to the number of levels of nested include files you can have, your compiler might run out of stack space while trying to include an inordinately high number of files. This number varies according to your hardware configuration and possibly your compiler.
-
What is #line used for?
The #line preprocessor directive is used to reset the values of the _ _LINE_ _ and _ _FILE_ _ symbols, respectively. This directive is commonly used in fourth-generation languages that generate C language source files.
-
What is a null pointer?
There are times when it’s necessary to have a pointer that doesn’t point to anything. The macro NULL, defined in <stddef.h>, has a value that’s guaranteed to be different from any valid pointer. NULL is a literal zero, possibly cast to void* or char*. Some people, notably C++ programmers, prefer to use 0 rather than NULL. The null pointer is used in three ways: 1) To stop indirection in...
-
Can you add pointers together? Why would you?
No, you can’t add pointers together. If you live at 1332 Lakeview Drive, and your neighbor lives at 1364 Lakeview, what’s 1332+1364? It’s a number, but it doesn’t mean anything. If you try to perform this type of calculation with pointers in a C program, your compiler will complain. The only time the addition of pointers might come up is if you try to add a pointer and the difference of two pointers....
-
What is the difference between far and near?
As described at the beginning of this chapter, some compilers for PC compatibles use two types of pointers. near pointers are 16 bits long and can address a 64KB range. far pointers are 32 bits long and can address a 1MB range. near pointers operate within a 64KB segment. There’s one segment for function addresses and one segment for data. far pointers have a 16-bit base (the segment address) and...
-
What is a modulus operator? What are the restrictions of a modulus operator?
A Modulus operator gives the remainder value. The result of x%y is obtained by(x-(x/y)*y). This operator is applied only to integral operands and cannot be applied to float or double.
-
What is a function and built-in function?
A large program is subdivided into a number of smaller programs or subprograms. Each subprogram specifies one or more actions to be performed for a large program.such subprograms are functions. The function supports only static and extern storage classes.By default, function assumes extern storage class.functions have global scope. Only register or auto storage class is allowed in the function...
-
What is the purpose of realloc( )?
the function realloc(ptr,n) uses two arguments.the first argument ptr is a pointer to a block of memory for which the size is to be altered.The second argument n specifies the new size.The size may be increased or decreased.If n is greater than the old size and if sufficient space is not available subsequent to the old region, the function realloc( ) may create a new region and all the old data are...
-
-
-
C Interview Questions
Ans