• +91 9971497814
  • info@interviewmaterial.com

Computer Interview Questions Answers

C Interview Questions Answers

Question - 101 : - What is a method?

Answer - 101 : - Method is a way of doing something, especially a systematic way; implies an orderly logical arrangement (usually in steps).

Question - 102 : - What is a static function?

Answer - 102 : - A static function is a function whose scope is limited to the current source file. Scope refers to the visibility of a function or variable. If the function or variable is visible outside of the current source file, it is said to have global, or external, scope. If the function or variable is not visible outside of the current source file, it is said to have local, or static, scope.

Question - 103 : - What will the following piece of code do int f(unsigned int x) { int i; for (i=0; x!0; x>>=1){ if (x & 0X1) i++; } return i; }

Answer - 103 : - returns the number of ones in the input parameter X

Question - 104 : - What will be printed as the result of the operation below: main() { int x=10, y=15; x = x++; y = ++y; printf(“%d %d\n”,x,y); }

Answer - 104 : - 11, 16

Question - 105 : - What is a pragma?

Answer - 105 : - The #pragma preprocessor directive allows each compiler to implement compiler-specific features that can be turned on and off with the #pragma statement. For instance, your compiler might support a feature called loop optimization. This feature can be invoked as a command-line option or as a #pragma directive. To implement this option using the #pragma directive, you would put the following line into your code: #pragma loop_opt(on) Conversely, you can turn off loop optimization by inserting the following line into your code: #pragma loop_opt(off)

Question - 106 : - How can I sort a linked list?

Answer - 106 : - Both the merge sort and the radix sort are good sorting algorithms to use for linked lists.

Question - 107 : - Why doesn't the following code give the desired result?

Answer - 107 : - int x = 3000, y = 2000 ; long int z = x * y ; Here the multiplication is carried out between two ints x and y, and the result that would overflow would be truncated before being assigned to the variable z of type long int. However, to get the correct output, we should use an explicit cast to force long arithmetic as shown below: long int z = ( long int ) x * y ; Note that ( long int )( x * y ) would not give the desired effect.

Question - 108 : - What will be printed as the result of the operation below: int x; int modifyvalue() { return(x+=10); } int changevalue(int x) { return(x+=1); } void main() { int x=10; x++; changevalue(x); x++; modifyvalue(); printf("First output:%d\n",x); x++; changeval

Answer - 108 : - 12 , 13 , 13

Question - 109 : - What is the purpose of realloc( )?

Answer - 109 : - 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 moved to the new region.

Question - 110 : - Why should I prototype a function?

Answer - 110 : - A function prototype tells the compiler what kind of arguments a function is looking to receive and what kind of return value a function is going to give back. This approach helps the compiler ensure that calls to a function are made correctly and that no erroneous type conversions are taking place.

Computer Contributors

krishan
Rajeev Katiyar
Yes Baroda

Share your email for latest updates

Name:
Email:

Our partners