• +91 9971497814
  • info@interviewmaterial.com

Computer Interview Questions Answers

C Interview Questions Answers

Question - 1 : - How can I sort things that are too large to bring into memory?

Answer - 1 : - 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 key/value pairs are sorted, the data is rearranged on disk into the correct order. If too large to fit in memory means that there are too many items to fit into memory at one time, the data can be sorted in groups that will fit into memory, and then the resulting files can be merged. A sort such as a radix sort can also be used as an external sort, by making each bucket in the sort a file. Even the quick sort can be an external sort. The data can be partitioned by writing it to two smaller files. When the partitions are small enough to fit, they are sorted in memory and concatenated to form the sorted file.

Question - 2 : - Compilation How to reduce a final size of executable?

Answer - 2 : - Size of the final executable can be reduced using dynamic linking for libraries.

Question - 3 : - What will be printed as the result of the operation below: #define swap(a,b) a=a+b;b=a-b;a=a-b; void main() { int x=5, y=10; swap (x,y); printf(“%d %d\n”,x,y) ; swap2(x,y); printf(“%d %d\n”,x,y) ; } int swap2(int a, int b) { int temp; temp=a; b=a; a=temp; return 0; } as x

Answer - 3 : - 10, 5

Question - 4 : - How can type-insensitive macros be created?

Answer - 4 : - A type-insensitive macro is a macro that performs the same basic operation on different data types. This task can be accomplished by using the concatenation operator to create a call to a type-sensitive function based on the parameter passed to the macro. The following program provides an example: #include #define SORT(data_type) sort_ ## data_type void sort_int(int** i); void sort_long(long** l); void sort_float(float** f); void sort_string(char** s); void main(void); void main(void) { int** ip; long** lp; float** fp; char** cp; ... sort(int)(ip); sort(long)(lp); sort(float)(fp); sort(char)(cp); ... } This program contains four functions to sort four different data types: int, long, float, and string (notice that only the function prototypes are included for brevity). A macro named SORT was created to take the data type passed to the macro and combine it with the sort_ string to form a valid function call that is appropriate for the data type being sorted. Thus, the string sort(int)(ip); translates into sort_int(ip); after being run through the preprocessor.

Question - 5 : - How can you restore a redirected standard stream?

Answer - 5 : - The preceding example showed how you can redirect a standard stream from within your program. But what if later in your program you wanted to restore the standard stream to its original state? By using the standard C library functions named dup() and fdopen(), you can restore a standard stream such as stdout to its original state. The dup() function duplicates a file handle. You can use the dup() function to save the file handle corresponding to the stdout standard stream. The fdopen() function opens a stream that has been duplicated with the dup() function.

Question - 6 : - What are x, y, y, u #define Atype int* typedef int *p; p x, z; Atype y, u;

Answer - 6 : -  x and z are pointers to int. y is a pointer to int but u is just an integer variable

Question - 7 : - what about this? Isn't this an array assignment? char a[] = "Hello, world!\n";

Answer - 7 : - No, that's an initialization. You are allowed to initialize arrays when you define them.

Question - 8 : - What is conversion operator?

Answer - 8 : - class can have a public method for specific data type conversions. for example: class Boo { double value; public: Boo(int i ) operator double() { return value; } }; Boo BooObject; double i = BooObject; // assigning object to variable i of type double. now conversion operator gets called to assign the value.

Question - 9 : - Can you add pointers together? Why would you?

Answer - 9 : - 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.

Question - 10 : - How do I know how many elements an array can hold?

Answer - 10 : - The amount of memory an array can consume depends on the data type of an array. In DOS environment, the amount of memory an array can consume depends on the current memory model (i.e. Tiny, Small, Large, Huge, etc.). In general an array cannot consume more than 64 kb. Consider following program, which shows the maximum number of elements an array of type int, float and char can have in case of Small memory model. main( ) { int i[32767] ; float f[16383] ; char s[65535] ; }

Computer Contributors

Rajeev Katiyar
Yes Baroda

Share your email for latest updates


Our partners